mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
merge with branch issue-109
This commit is contained in:
@@ -169,6 +169,19 @@ public class HttpRequest
|
|||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @since 1.14
|
||||||
|
*/
|
||||||
|
public boolean isDecodeGZip()
|
||||||
|
{
|
||||||
|
return decodeGZip;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,6 +201,22 @@ public class HttpRequest
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param decodeGZip
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @since 1.14
|
||||||
|
*/
|
||||||
|
public HttpRequest setDecodeGZip(boolean decodeGZip)
|
||||||
|
{
|
||||||
|
this.decodeGZip = decodeGZip;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -247,6 +276,9 @@ public class HttpRequest
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private boolean decodeGZip = false;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Map<String, List<String>> headers;
|
private Map<String, List<String>> headers;
|
||||||
|
|
||||||
|
|||||||
@@ -87,15 +87,15 @@ public class HgConfigResource
|
|||||||
*
|
*
|
||||||
* @param client
|
* @param client
|
||||||
* @param handler
|
* @param handler
|
||||||
* @param cacheManager
|
* @param pkgReader
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public HgConfigResource(HttpClient client, HgRepositoryHandler handler,
|
public HgConfigResource(HttpClient client, HgRepositoryHandler handler,
|
||||||
CacheManager cacheManager)
|
HgPackageReader pkgReader)
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.pkgReader = new HgPackageReader(cacheManager);
|
this.pkgReader = pkgReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
@@ -35,12 +35,18 @@ package sonia.scm.installer;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.PlatformType;
|
import sonia.scm.PlatformType;
|
||||||
import sonia.scm.cache.Cache;
|
import sonia.scm.cache.Cache;
|
||||||
import sonia.scm.cache.CacheManager;
|
import sonia.scm.cache.CacheManager;
|
||||||
|
import sonia.scm.net.HttpClient;
|
||||||
|
import sonia.scm.net.HttpRequest;
|
||||||
|
import sonia.scm.net.HttpResponse;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
import sonia.scm.util.SystemUtil;
|
import sonia.scm.util.SystemUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
@@ -50,11 +56,8 @@ import sonia.scm.util.Util;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
|
|
||||||
@@ -83,10 +86,14 @@ public class HgPackageReader
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param cacheManager
|
* @param cacheManager
|
||||||
|
* @param httpClientProvider
|
||||||
*/
|
*/
|
||||||
public HgPackageReader(CacheManager cacheManager)
|
@Inject
|
||||||
|
public HgPackageReader(CacheManager cacheManager,
|
||||||
|
Provider<HttpClient> httpClientProvider)
|
||||||
{
|
{
|
||||||
cache = cacheManager.getCache(String.class, HgPackages.class, CACHENAME);
|
cache = cacheManager.getCache(String.class, HgPackages.class, CACHENAME);
|
||||||
|
this.httpClientProvider = httpClientProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -216,17 +223,13 @@ public class HgPackageReader
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL url = new URL(PACKAGEURL);
|
HttpRequest request = new HttpRequest(PACKAGEURL);
|
||||||
|
|
||||||
if (PACKAGEURL.endsWith(".gz"))
|
request.setDecodeGZip(true);
|
||||||
{
|
|
||||||
input = new GZIPInputStream(url.openStream());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
input = url.openStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
HttpResponse response = httpClientProvider.get().get(request);
|
||||||
|
|
||||||
|
input = response.getContent();
|
||||||
packages = JAXB.unmarshal(input, HgPackages.class);
|
packages = JAXB.unmarshal(input, HgPackages.class);
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
@@ -251,4 +254,7 @@ public class HgPackageReader
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Cache<String, HgPackages> cache;
|
private Cache<String, HgPackages> cache;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Provider<HttpClient> httpClientProvider;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ package sonia.scm.web;
|
|||||||
|
|
||||||
import com.google.inject.servlet.ServletModule;
|
import com.google.inject.servlet.ServletModule;
|
||||||
|
|
||||||
|
import sonia.scm.installer.HgPackageReader;
|
||||||
import sonia.scm.plugin.ext.Extension;
|
import sonia.scm.plugin.ext.Extension;
|
||||||
import sonia.scm.repository.HgContext;
|
import sonia.scm.repository.HgContext;
|
||||||
import sonia.scm.repository.HgHookManager;
|
import sonia.scm.repository.HgHookManager;
|
||||||
@@ -67,6 +68,9 @@ public class HgServletModule extends ServletModule
|
|||||||
{
|
{
|
||||||
bind(HgContext.class);
|
bind(HgContext.class);
|
||||||
bind(HgHookManager.class);
|
bind(HgHookManager.class);
|
||||||
|
bind(HgPackageReader.class);
|
||||||
|
|
||||||
|
// bind servlets
|
||||||
serve(MAPPING_HOOK).with(HgHookCallbackServlet.class);
|
serve(MAPPING_HOOK).with(HgHookCallbackServlet.class);
|
||||||
|
|
||||||
// register hg cgi servlet
|
// register hg cgi servlet
|
||||||
|
|||||||
@@ -251,7 +251,8 @@ public class URLHttpClient implements HttpClient
|
|||||||
{
|
{
|
||||||
String url = createGetUrl(request.getUrl(), request.getParameters());
|
String url = createGetUrl(request.getUrl(), request.getParameters());
|
||||||
|
|
||||||
return new URLHttpResponse(openConnection(request, url));
|
return new URLHttpResponse(openConnection(request, url),
|
||||||
|
request.isDecodeGZip());
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
@@ -70,8 +70,21 @@ public class URLHttpResponse implements HttpResponse
|
|||||||
* @param connection
|
* @param connection
|
||||||
*/
|
*/
|
||||||
public URLHttpResponse(URLConnection connection)
|
public URLHttpResponse(URLConnection connection)
|
||||||
|
{
|
||||||
|
this(connection, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param connection
|
||||||
|
* @param decodeGZip
|
||||||
|
*/
|
||||||
|
public URLHttpResponse(URLConnection connection, boolean decodeGZip)
|
||||||
{
|
{
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
this.decodeGZip = decodeGZip;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -114,7 +127,7 @@ public class URLHttpResponse implements HttpResponse
|
|||||||
String enc = connection.getContentEncoding();
|
String enc = connection.getContentEncoding();
|
||||||
InputStream input = null;
|
InputStream input = null;
|
||||||
|
|
||||||
if (Util.isNotEmpty(enc) && enc.contains(ENCODING_GZIP))
|
if (decodeGZip || (Util.isNotEmpty(enc) && enc.contains(ENCODING_GZIP)))
|
||||||
{
|
{
|
||||||
input = new GZIPInputStream(connection.getInputStream());
|
input = new GZIPInputStream(connection.getInputStream());
|
||||||
}
|
}
|
||||||
@@ -215,8 +228,11 @@ public class URLHttpResponse implements HttpResponse
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private boolean clientClose = false;
|
private URLConnection connection;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private URLConnection connection;
|
private boolean decodeGZip = false;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private boolean clientClose = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user