You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2009/10/06 14:21:50 UTC

svn commit: r822238 - in /httpcomponents/httpclient/trunk/src/docbkx: fundamentals.xml httpagent.xml

Author: olegk
Date: Tue Oct  6 12:21:50 2009
New Revision: 822238

URL: http://svn.apache.org/viewvc?rev=822238&view=rev
Log:
HTTPCLIENT-834: Tutorial section on transparent content encoding support
Contributed by James Abley <james.abley at gmail.com>

Modified:
    httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml
    httpcomponents/httpclient/trunk/src/docbkx/httpagent.xml

Modified: httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml?rev=822238&r1=822237&r2=822238&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml (original)
+++ httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml Tue Oct  6 12:21:50 2009
@@ -703,7 +703,7 @@
             blocked in an I/O operation is guaranteed to unblock by throwing a
                 <exceptionname>InterruptedIOException</exceptionname></para>
     </section>
-    <section>
+    <section id="protocol_interceptors">
         <title>HTTP protocol interceptors</title>
         <para>HTTP protocol interceptor is a routine that implements a specific aspect of the HTTP
             protocol. Usually protocol interceptors are expected to act upon one specific header or

Modified: httpcomponents/httpclient/trunk/src/docbkx/httpagent.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/src/docbkx/httpagent.xml?rev=822238&r1=822237&r2=822238&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/src/docbkx/httpagent.xml (original)
+++ httpcomponents/httpclient/trunk/src/docbkx/httpagent.xml Tue Oct  6 12:21:50 2009
@@ -201,4 +201,44 @@
 System.out.println("Final request method: " + req.getMethod());
 ]]></programlisting>
     </section>
+  <section>
+    <title>Compressed response content</title>
+    <para>
+      The <classname>ContentEncodingHttpClient</classname> is a simple sub-class of
+      <classname>DefaultHttpClient</classname> which adds support indicating to servers that it will 
+      support <literal>gzip</literal> and <literal>deflate</literal> compressed responses. It does 
+      this via the existing published APIs of <link linkend="protocol_interceptors">HTTP Protocol 
+      Interceptors </link>. Depending on the type of response (text will compress well versus 
+      images, which are typically already well-compressed), this can speed up responses due to the 
+      smaller amount of network traffic involved, along with saving bandwidth, which can be 
+      important in mobile environments. The <classname>RequestAcceptEncoding</classname>
+      and <classname>ResponseContentEncoding</classname> interceptors used as also part of the 
+      published API and can be used by other <interfacename>DefaultHttpClient</interfacename>
+      implementations. These provide transparent handling of <literal>gzip</literal> and 
+      <literal>deflate</literal> encoding, so it will not be apparent to clients that this 
+      processing has happened.
+    </para>
+    <programlisting><![CDATA[
+ContentEncodingHttpClient httpclient = new ContentEncodingHttpClient();
+HttpGet httpget = new HttpGet("http://www.yahoo.com/");
+HttpResponse response = httpclient.execute(httpget);
+
+Header h = rsp.getFirstHeader("Content-Encoding");
+if (h != null) {
+    System.out.println("----------------------------------------");
+    System.out.println("Response is " + h.getValue() + " encoded");
+    System.out.println("----------------------------------------");
+}
+]]></programlisting>
+    <para>
+      One can also add the <classname>RequestAcceptEncoding</classname> and 
+      <classname>ResponseContentEncoding</classname> interceptors to an instance of the 
+      <classname>DefaultHttpClient</classname>, if desired.
+    </para>
+    <programlisting><![CDATA[
+DefaultHttpClient httpclient = new DefaultHttpClient();
+httpclient.addRequestInterceptor(new RequestAcceptEncoding());
+httpclient.addResponseInterceptor(new ResponseContentEncoding());
+]]></programlisting>
+  </section>
 </chapter>