added parameter for gzip encoding to HttpRequest

This commit is contained in:
Sebastian Sdorra
2012-04-05 16:49:42 +02:00
parent 7b74ef7820
commit d6255d887e
3 changed files with 53 additions and 4 deletions

View File

@@ -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;

View File

@@ -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 --------------------------------------------------------------

View File

@@ -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;
} }