mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
added support for gzip encoding
This commit is contained in:
@@ -72,6 +72,12 @@ public class URLHttpClient implements HttpClient
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ENCODING = "UTF-8";
|
public static final String ENCODING = "UTF-8";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String HEADER_ACCEPT_ENCODING_VALUE = "gzip";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String HEADER_USERAGENT = "User-Agent";
|
public static final String HEADER_USERAGENT = "User-Agent";
|
||||||
|
|
||||||
@@ -334,6 +340,8 @@ public class URLHttpClient implements HttpClient
|
|||||||
connection = url.openConnection();
|
connection = url.openConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connection.setRequestProperty(HEADER_ACCEPT_ENCODING,
|
||||||
|
HEADER_ACCEPT_ENCODING_VALUE);
|
||||||
connection.setRequestProperty(
|
connection.setRequestProperty(
|
||||||
HEADER_USERAGENT, HEADER_USERAGENT_VALUE.concat(context.getVersion()));
|
HEADER_USERAGENT, HEADER_USERAGENT_VALUE.concat(context.getVersion()));
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ package sonia.scm.net;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ import java.net.URLConnection;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -56,6 +58,11 @@ import java.util.Map;
|
|||||||
public class URLHttpResponse implements HttpResponse
|
public class URLHttpResponse implements HttpResponse
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String ENCODING_GZIP = "gzip";
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
@@ -104,7 +111,19 @@ public class URLHttpResponse implements HttpResponse
|
|||||||
{
|
{
|
||||||
clientClose = true;
|
clientClose = true;
|
||||||
|
|
||||||
return connection.getInputStream();
|
String enc = connection.getContentEncoding();
|
||||||
|
InputStream input = null;
|
||||||
|
|
||||||
|
if (Util.isNotEmpty(enc) && enc.contains(ENCODING_GZIP))
|
||||||
|
{
|
||||||
|
input = new GZIPInputStream(connection.getInputStream());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
input = connection.getInputStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,15 +147,7 @@ public class URLHttpResponse implements HttpResponse
|
|||||||
baos = new ByteArrayOutputStream();
|
baos = new ByteArrayOutputStream();
|
||||||
IOUtil.copy(in, baos);
|
IOUtil.copy(in, baos);
|
||||||
baos.flush();
|
baos.flush();
|
||||||
|
result = new String(baos.toByteArray());
|
||||||
String enc = connection.getContentEncoding();
|
|
||||||
|
|
||||||
if (enc == null)
|
|
||||||
{
|
|
||||||
enc = "UTF-8";
|
|
||||||
}
|
|
||||||
|
|
||||||
result = new String(baos.toByteArray(), enc);
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user