Nobody to revue my GZIP patch and commit to HEAD ?
On Fri, 4 Mar 2005 16:25:45 +0100, Henri Gomez <[EMAIL PROTECTED]> wrote:
> Here is a patch to support GZIP in CommonsXmlRpcTransport.java :
>
> Anyone to revue and commit to HEAD ?
>
> Regards
>
> ---
>
> --- CommonsXmlRpcTransport.java.orig 2005-03-04 15:32:24.000000000 +0100
> +++ CommonsXmlRpcTransport.java 2005-03-04 15:33:50.000000000 +0100
> @@ -59,6 +59,8 @@
> import java.io.InputStream;
> import java.io.IOException;
> import java.net.URL;
> +import java.util.zip.GZIPInputStream;
> +
> import org.apache.commons.httpclient.Header;
> import org.apache.commons.httpclient.HostConfiguration;
> import org.apache.commons.httpclient.HttpClient;
> @@ -97,11 +99,16 @@
> private HttpClient client;
> private final Header userAgentHeader = new Header("User-Agent",
> XmlRpc.version);
> private boolean http11 = false; // defaults to HTTP 1.0
> + private boolean gzip = false;
>
> public InputStream sendXmlRpc(byte[] request) throws IOException,
> XmlRpcClientException {
> PostMethod method = new PostMethod(url.toString());
> method.setHttp11(http11);
> method.setRequestHeader(new Header("Content-Type", "text/xml"));
> +
> + if (gzip)
> + method.setRequestHeader(new Header("Accept-Encoding",
> "gzip"));
> +
> method.setRequestHeader(userAgentHeader);
> // TODO: authentication not implemented yet
> method.setRequestBody(new ByteArrayInputStream(request));
> @@ -109,14 +116,32 @@
> HostConfiguration hostConfig = new HostConfiguration();
> hostConfig.setHost(hostURI);
> client.executeMethod(hostConfig, method);
> - return method.getResponseBodyAsStream();
> +
> + boolean lgzipo = false;
> +
> + Header lHeader = method.getResponseHeader( "Content-Encoding" );
> + if ( lHeader != null ) {
> + String lValue = lHeader.getValue();
> + if ( lValue != null )
> + lgzipo = (lValue.indexOf( "gzip" ) >= 0);
> + }
> +
> + if (lgzipo)
> + return( new GZIPInputStream(
> method.getResponseBodyAsStream() ) );
> + else
> + return method.getResponseBodyAsStream();
> }
>
> public void setHttp11(boolean http11) {
> this.http11 = http11;
> }
>
> + public void setGzip(boolean gzip) {
> + this.gzip = gzip;
> + }
> +
> public void setUserAgent(String userAgent) {
> userAgentHeader.setValue(userAgent);
> }
> }
> +
>