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 2023/02/26 16:12:58 UTC

svn commit: r1907880 [1/4] - in /httpcomponents/site: components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/ httpcomponents-client-4.5.x/

Author: olegk
Date: Sun Feb 26 16:12:58 2023
New Revision: 1907880

URL: http://svn.apache.org/viewvc?rev=1907880&view=rev
Log:
HTTPCLIENT-2260: restored missing HttpClient 4.5 tutorial

Added:
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/advanced.html
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/authentication.html
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/caching.html
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/connmgmt.html
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/fluent.html
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/fundamentals.html
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/index.html
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/preface.html
    httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/statemgmt.html
    httpcomponents/site/httpcomponents-client-4.5.x/4.5.14   (with props)
Modified:
    httpcomponents/site/httpcomponents-client-4.5.x/4.5.13

Added: httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/advanced.html
URL: http://svn.apache.org/viewvc/httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/advanced.html?rev=1907880&view=auto
==============================================================================
--- httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/advanced.html (added)
+++ httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/advanced.html Sun Feb 26 16:12:58 2023
@@ -0,0 +1,250 @@
+<html><head>
+      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+   <title>Chapter&nbsp;7.&nbsp;Advanced topics</title><link rel="stylesheet" type="text/css" href="css/hc-tutorial.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="index.html" title="HttpClient Tutorial"><link rel="up" href="index.html" title="HttpClient Tutorial"><link rel="prev" href="caching.html" title="Chapter&nbsp;6.&nbsp;HTTP Caching"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div xmlns:fo="http://www.w3.org/1999/XSL/Format" class="banner"><a class="bannerLeft" href="http://www.apache.org/" title="Apache Software Foundation"><img style="border:none;" src="images/asf_logo_wide.gif"></a><a class="bannerRight" href="http://hc.apache.org/httpcomponents-client-ga/" title="Apache HttpComponents Client"><img style="border:none;" src="images/hc_logo.png"></a><div class="clear"></div></div><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">C
 hapter&nbsp;7.&nbsp;Advanced topics</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="caching.html">Prev</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;</td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="advanced"></a>Chapter&nbsp;7.&nbsp;Advanced topics</h1></div></div></div>
+    
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e913"></a>7.1.&nbsp;Custom client connections</h2></div></div></div>
+        
+        <p>In certain situations it may be necessary to customize the way HTTP messages get
+            transmitted across the wire beyond what is possible using HTTP parameters in
+            order to be able to deal non-standard, non-compliant behaviours. For instance, for web
+            crawlers it may be necessary to force HttpClient into accepting malformed response heads
+            in order to salvage the content of the messages. </p>
+        <p>Usually the process of plugging in a custom message parser or a custom connection
+            implementation involves several steps:</p>
+        <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
+                <p>Provide a custom <code class="interfacename">LineParser</code> /
+                        <code class="interfacename">LineFormatter</code> interface implementation.
+                    Implement message parsing / formatting logic as required.</p>
+                <pre class="programlisting">
+class MyLineParser extends BasicLineParser {
+
+    @Override
+    public Header parseHeader(
+            CharArrayBuffer buffer) throws ParseException {
+        try {
+            return super.parseHeader(buffer);
+        } catch (ParseException ex) {
+            // Suppress ParseException exception
+            return new BasicHeader(buffer.toString(), null);
+        }
+    }
+
+}
+</pre>
+            </li><li class="listitem">
+                <p>Provide a custom <code class="interfacename">HttpConnectionFactory</code>
+                    implementation. Replace default request writer and / or response parser
+                    with custom ones as required. </p>
+                <pre class="programlisting">
+HttpConnectionFactory&lt;HttpRoute, ManagedHttpClientConnection&gt; connFactory =
+        new ManagedHttpClientConnectionFactory(
+            new DefaultHttpRequestWriterFactory(),
+            new DefaultHttpResponseParserFactory(
+                    new MyLineParser(), new DefaultHttpResponseFactory()));
+</pre>
+            </li><li class="listitem">
+                <p>Configure HttpClient to use the custom connection factory.</p>
+                <pre class="programlisting">
+PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(
+    connFactory);
+CloseableHttpClient httpclient = HttpClients.custom()
+        .setConnectionManager(cm)
+        .build();
+</pre>
+            </li></ul></div>
+    </div>
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="stateful_conn"></a>7.2.&nbsp;Stateful HTTP connections</h2></div></div></div>
+        
+        <p>While HTTP specification assumes that session state information is always embedded in
+            HTTP messages in the form of HTTP cookies and therefore HTTP connections are always
+            stateless, this assumption does not always hold true in real life. There are cases when
+            HTTP connections are created with a particular user identity or within a particular
+            security context and therefore cannot be shared with other users and can be reused by
+            the same user only. Examples of such stateful HTTP connections are
+                <code class="literal">NTLM</code> authenticated connections and SSL connections with client
+            certificate authentication.</p>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e934"></a>7.2.1.&nbsp;User token handler</h3></div></div></div>
+            
+            <p>HttpClient relies on <code class="interfacename">UserTokenHandler</code> interface to
+                determine if the given execution context is user specific or not. The token object
+                returned by this handler is expected to uniquely identify the current user if the
+                context is user specific or to be null if the context does not contain any resources
+                or details specific to the current user. The user token will be used to ensure that
+                user specific resources will not be shared with or reused by other users.</p>
+            <p>The default implementation of the <code class="interfacename">UserTokenHandler</code>
+                interface uses an instance of Principal class to represent a state object for HTTP
+                connections, if it can be obtained from the given execution context.
+                    <code class="classname">DefaultUserTokenHandler</code> will use the user principal of
+                connection based authentication schemes such as <code class="literal">NTLM</code> or that of
+                the SSL session with client authentication turned on. If both are unavailable, null
+                token will be returned.</p>
+            <pre class="programlisting">
+CloseableHttpClient httpclient = HttpClients.createDefault();
+HttpClientContext context = HttpClientContext.create();
+HttpGet httpget = new HttpGet("http://localhost:8080/");
+CloseableHttpResponse response = httpclient.execute(httpget, context);
+try {
+    Principal principal = context.getUserToken(Principal.class);
+    System.out.println(principal);
+} finally {
+    response.close();
+}
+</pre>
+            <p>Users can provide a custom implementation if the default one does not satisfy
+                their needs:</p>
+            <pre class="programlisting">
+UserTokenHandler userTokenHandler = new UserTokenHandler() {
+
+    public Object getUserToken(HttpContext context) {
+        return context.getAttribute("my-token");
+    }
+
+};
+CloseableHttpClient httpclient = HttpClients.custom()
+        .setUserTokenHandler(userTokenHandler)
+        .build();
+</pre>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e945"></a>7.2.2.&nbsp;Persistent stateful connections</h3></div></div></div>
+            
+            <p>Please note that a persistent connection that carries a state object can be reused
+                only if the same state object is bound to the execution context when requests
+                are executed. So, it is really important to ensure the either same context is
+                reused for execution of subsequent HTTP requests by the same user or the user
+                token is bound to the context prior to request execution.</p>
+            <pre class="programlisting">
+CloseableHttpClient httpclient = HttpClients.createDefault();
+HttpClientContext context1 = HttpClientContext.create();
+HttpGet httpget1 = new HttpGet("http://localhost:8080/");
+CloseableHttpResponse response1 = httpclient.execute(httpget1, context1);
+try {
+    HttpEntity entity1 = response1.getEntity();
+} finally {
+    response1.close();
+}
+Principal principal = context1.getUserToken(Principal.class);
+
+HttpClientContext context2 = HttpClientContext.create();
+context2.setUserToken(principal);
+HttpGet httpget2 = new HttpGet("http://localhost:8080/");
+CloseableHttpResponse response2 = httpclient.execute(httpget2, context2);
+try {
+    HttpEntity entity2 = response2.getEntity();
+} finally {
+    response2.close();
+}
+</pre>
+        </div>
+    </div>
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e949"></a>7.3.&nbsp;Using the FutureRequestExecutionService</h2></div></div></div>
+        
+
+        <p>Using the FutureRequestExecutionService, you can schedule http calls and treat the response
+            as a Future. This is useful when e.g. making multiple calls to a web service. The advantage of using
+            the FutureRequestExecutionService is that you can use multiple threads to schedule requests concurrently, set timeouts on
+            the tasks, or cancel them when a response is no longer necessary.
+        </p>
+
+        <p>FutureRequestExecutionService wraps the request with a HttpRequestFutureTask, which extends FutureTask. This
+        class allows you to cancel the task as well as keep track of various metrics such as request duration.</p>
+
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e953"></a>7.3.1.&nbsp;Creating the FutureRequestExecutionService</h3></div></div></div>
+            
+            <p>The constructor for the futureRequestExecutionService takes any existing httpClient instance and an ExecutorService
+            instance. When configuring both, it is important to align the maximum number of connections with the number of threads
+            you are going to use. When there are more threads than connections, the connections may start timing out because there are no
+            available connections. When there are more connections than threads, the futureRequestExecutionService will not use all of them</p>
+
+            <pre class="programlisting">
+HttpClient httpClient = HttpClientBuilder.create().setMaxConnPerRoute(5).build();
+ExecutorService executorService = Executors.newFixedThreadPool(5);
+FutureRequestExecutionService futureRequestExecutionService =
+    new FutureRequestExecutionService(httpClient, executorService);
+</pre>
+        </div>
+
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e957"></a>7.3.2.&nbsp;Scheduling requests</h3></div></div></div>
+            
+            <p>To schedule a request, simply provide a HttpUriRequest, HttpContext, and a ResponseHandler. Because
+                the request is processed by the executor service, a ResponseHandler is mandatory.</p>
+
+            <pre class="programlisting">
+private final class OkidokiHandler implements ResponseHandler&lt;Boolean&gt; {
+    public Boolean handleResponse(
+            final HttpResponse response) throws ClientProtocolException, IOException {
+        return response.getStatusLine().getStatusCode() == 200;
+    }
+}
+
+HttpRequestFutureTask&lt;Boolean&gt; task = futureRequestExecutionService.execute(
+    new HttpGet("http://www.google.com"), HttpClientContext.create(),
+    new OkidokiHandler());
+// blocks until the request complete and then returns true if you can connect to Google
+boolean ok=task.get();
+</pre>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e961"></a>7.3.3.&nbsp;Canceling tasks</h3></div></div></div>
+            
+            <p>Scheduled tasks may be cancelled. If the task is not yet executing but merely queued for execution, it simply will never execute. If it is executing and the mayInterruptIfRunning parameter is set to true, abort() will be called on the request; otherwise the response will simply be ignored but the request will be allowed to complete normally. Any subsequent calls to task.get() will fail with an IllegalStateException. It should be noticed that canceling tasks merely frees up the client side resources. The request may actually be handled normally on the server side. </p>
+            <pre class="programlisting">
+task.cancel(true)
+task.get() // throws an Exception
+</pre>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e965"></a>7.3.4.&nbsp;Callbacks</h3></div></div></div>
+            
+            <p>Instead of manually calling task.get(), you can also use a FutureCallback instance that gets callbacks when the request completes. This is the
+                same interface as is used in HttpAsyncClient</p>
+                <pre class="programlisting">
+
+private final class MyCallback implements FutureCallback&lt;Boolean&gt; {
+
+    public void failed(final Exception ex) {
+        // do something
+    }
+
+    public void completed(final Boolean result) {
+        // do something
+    }
+
+    public void cancelled() {
+        // do something
+    }
+}
+
+HttpRequestFutureTask&lt;Boolean&gt; task = futureRequestExecutionService.execute(
+    new HttpGet("http://www.google.com"), HttpClientContext.create(),
+    new OkidokiHandler(), new MyCallback());
+</pre>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e969"></a>7.3.5.&nbsp;Metrics</h3></div></div></div>
+            
+            <p>FutureRequestExecutionService is typically used in applications that make large amounts of
+                web service calls. To facilitate e.g. monitoring or configuration tuning, the FutureRequestExecutionService keeps
+                track of several metrics.</p>
+            <p>Each HttpRequestFutureTask provides methods to get the time the task was scheduled,
+                started, and ended. Additionally, request and task duration are available as well. These
+                metrics are aggregated in the FutureRequestExecutionService in a FutureRequestExecutionMetrics
+                instance that may be accessed through FutureRequestExecutionService.metrics().</p>
+            <pre class="programlisting">
+task.scheduledTime() // returns the timestamp the task was scheduled
+task.startedTime() // returns the timestamp when the task was started
+task.endedTime() // returns the timestamp when the task was done executing
+task.requestDuration // returns the duration of the http request
+task.taskDuration // returns the duration of the task from the moment it was scheduled
+
+FutureRequestExecutionMetrics metrics = futureRequestExecutionService.metrics()
+metrics.getActiveConnectionCount() // currently active connections
+metrics.getScheduledConnectionCount(); // currently scheduled connections
+metrics.getSuccessfulConnectionCount(); // total number of successful requests
+metrics.getSuccessfulConnectionAverageDuration(); // average request duration
+metrics.getFailedConnectionCount(); // total number of failed tasks
+metrics.getFailedConnectionAverageDuration(); // average duration of failed tasks
+metrics.getTaskCount(); // total number of tasks scheduled
+metrics.getRequestCount(); // total number of requests
+metrics.getRequestAverageDuration(); // average request duration
+metrics.getTaskAverageDuration(); // average task duration
+</pre>
+        </div>
+    </div>
+</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="caching.html">Prev</a>&nbsp;</td><td width="20%" align="center">&nbsp;</td><td width="40%" align="right">&nbsp;</td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;6.&nbsp;HTTP Caching&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;</td></tr></table></div></body></html>
\ No newline at end of file

Added: httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/authentication.html
URL: http://svn.apache.org/viewvc/httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/authentication.html?rev=1907880&view=auto
==============================================================================
--- httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/authentication.html (added)
+++ httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/authentication.html Sun Feb 26 16:12:58 2023
@@ -0,0 +1,477 @@
+<html><head>
+      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+   <title>Chapter&nbsp;4.&nbsp;HTTP authentication</title><link rel="stylesheet" type="text/css" href="css/hc-tutorial.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="index.html" title="HttpClient Tutorial"><link rel="up" href="index.html" title="HttpClient Tutorial"><link rel="prev" href="statemgmt.html" title="Chapter&nbsp;3.&nbsp;HTTP state management"><link rel="next" href="fluent.html" title="Chapter&nbsp;5.&nbsp;Fluent API"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div xmlns:fo="http://www.w3.org/1999/XSL/Format" class="banner"><a class="bannerLeft" href="http://www.apache.org/" title="Apache Software Foundation"><img style="border:none;" src="images/asf_logo_wide.gif"></a><a class="bannerRight" href="http://hc.apache.org/httpcomponents-client-ga/" title="Apache HttpComponents Client"><img style="border:none;" src="images/hc_logo.png"></a><div class="clear"></div></div><div class="navh
 eader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;4.&nbsp;HTTP authentication</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="statemgmt.html">Prev</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="fluent.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="authentication"></a>Chapter&nbsp;4.&nbsp;HTTP authentication</h1></div></div></div>
+    
+    <p>HttpClient provides full support for authentication schemes defined by the HTTP standard
+        specification as well as a number of widely used non-standard authentication schemes such 
+        as <code class="literal">NTLM</code> and <code class="literal">SPNEGO</code>.</p>
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e613"></a>4.1.&nbsp;User credentials</h2></div></div></div>
+        
+        <p>Any process of user authentication requires a set of credentials that can be used to
+            establish user identity. In the simplest form user credentials can be just a user name /
+            password pair. <code class="classname">UsernamePasswordCredentials</code> represents a set of
+            credentials consisting of a security principal and a password in clear text. This
+            implementation is sufficient for standard authentication schemes defined by the HTTP
+            standard specification.</p>
+        <pre class="programlisting">
+UsernamePasswordCredentials creds = new UsernamePasswordCredentials("user", "pwd");
+System.out.println(creds.getUserPrincipal().getName());
+System.out.println(creds.getPassword());
+        </pre>
+        <p>stdout &gt;</p>
+        <pre class="programlisting">
+user
+pwd
+</pre>
+        <p><code class="classname">NTCredentials</code> is a Microsoft Windows specific implementation
+            that includes in addition to the user name / password pair a set of additional Windows
+            specific attributes such as the name of the user domain. In a Microsoft Windows network
+            the same user can belong to multiple domains each with a different set of
+            authorizations.</p>
+        <pre class="programlisting">
+NTCredentials creds = new NTCredentials("user", "pwd", "workstation", "domain");
+System.out.println(creds.getUserPrincipal().getName());
+System.out.println(creds.getPassword());
+</pre>
+        <p>stdout &gt;</p>
+        <pre class="programlisting">
+DOMAIN/user
+pwd
+</pre>
+    </div>
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e625"></a>4.2.&nbsp;Authentication schemes</h2></div></div></div>
+        
+        <p>The <code class="interfacename">AuthScheme</code> interface represents an abstract
+            challenge-response oriented authentication scheme. An authentication scheme is expected
+            to support the following functions:</p>
+        <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
+                <p>Parse and process the challenge sent by the target server in response to
+                    request for a protected resource.</p>
+            </li><li class="listitem">
+                <p>Provide properties of the processed challenge: the authentication scheme type
+                    and its parameters, such the realm this authentication scheme is applicable to,
+                    if available</p>
+            </li><li class="listitem">
+                <p>Generate the authorization string for the given set of credentials and the HTTP
+                    request in response to the actual authorization challenge.</p>
+            </li></ul></div>
+        <p>Please note that authentication schemes may be stateful involving a series of
+            challenge-response exchanges.</p>
+        <p>HttpClient ships with several <code class="interfacename">AuthScheme</code>
+            implementations:</p>
+        <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
+                <p>
+                    <b>Basic:&nbsp;</b>
+                    Basic authentication scheme as defined in RFC 2617. This authentication
+                        scheme is insecure, as the credentials are transmitted in clear text.
+                        Despite its insecurity Basic authentication scheme is perfectly adequate if
+                        used in combination with the TLS/SSL encryption.
+                </p>
+            </li><li class="listitem">
+                <p>
+                    <b>Digest.&nbsp;</b>
+                    Digest authentication scheme as defined in RFC 2617. Digest authentication
+                        scheme is significantly more secure than Basic and can be a good choice for
+                        those applications that do not want the overhead of full transport security
+                        through TLS/SSL encryption.
+                </p>
+            </li><li class="listitem">
+                <p>
+                    <b>NTLM:&nbsp;</b>
+                    NTLM is a proprietary authentication scheme developed by Microsoft and
+                        optimized for Windows platforms. NTLM is believed to be more secure than
+                        Digest.
+                </p>
+            </li><li class="listitem">
+                <p>
+                    <b>SPNEGO:&nbsp;</b>
+                    <code class="literal">SPNEGO</code> (<span class="emphasis"><em>S</em></span>imple and
+                            <span class="emphasis"><em>P</em></span>rotected <code class="literal">GSSAPI</code>
+                        <span class="emphasis"><em>Nego</em></span>tiation Mechanism) is a <code class="literal">GSSAPI</code>
+                        "pseudo mechanism" that is used to negotiate one of a number of possible
+                        real mechanisms. SPNEGO's most visible use is in Microsoft's <code class="literal">HTTP
+                            Negotiate</code> authentication extension. The negotiable
+                        sub-mechanisms include NTLM and Kerberos supported by Active Directory.
+                        At present HttpClient only supports the Kerberos sub-mechanism. 
+                </p>
+            </li><li class="listitem">
+                <p>
+                    <b>Kerberos:&nbsp;</b>
+                    Kerberos authentication implementation. 
+                </p>
+            </li></ul></div>
+    </div>
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e667"></a>4.3.&nbsp;Credentials provider</h2></div></div></div>
+        
+        <p>Credentials providers are intended to maintain a set of user credentials and to be
+            able to produce user credentials for a particular authentication scope. Authentication
+            scope consists of a host name, a port number, a realm name and an authentication scheme
+            name. When registering credentials with the credentials provider one can provide a wild
+            card (any host, any port, any realm, any scheme) instead of a concrete attribute value.
+            The credentials provider is then expected to be able to find the closest match for a
+            particular scope if the direct match cannot be found.</p>
+        <p>HttpClient can work with any physical representation of a credentials provider that
+            implements the <code class="interfacename">CredentialsProvider</code> interface. The default
+                <code class="interfacename">CredentialsProvider</code> implementation called
+                <code class="classname">BasicCredentialsProvider</code> is a simple implementation backed by
+            a <code class="classname">java.util.HashMap</code>.</p>
+        <pre class="programlisting">
+CredentialsProvider credsProvider = new BasicCredentialsProvider();
+credsProvider.setCredentials(
+    new AuthScope("somehost", AuthScope.ANY_PORT), 
+    new UsernamePasswordCredentials("u1", "p1"));
+credsProvider.setCredentials(
+    new AuthScope("somehost", 8080), 
+    new UsernamePasswordCredentials("u2", "p2"));
+credsProvider.setCredentials(
+    new AuthScope("otherhost", 8080, AuthScope.ANY_REALM, "ntlm"), 
+    new UsernamePasswordCredentials("u3", "p3"));
+
+System.out.println(credsProvider.getCredentials(
+    new AuthScope("somehost", 80, "realm", "basic")));
+System.out.println(credsProvider.getCredentials(
+    new AuthScope("somehost", 8080, "realm", "basic")));
+System.out.println(credsProvider.getCredentials(
+    new AuthScope("otherhost", 8080, "realm", "basic")));
+System.out.println(credsProvider.getCredentials(
+    new AuthScope("otherhost", 8080, null, "ntlm")));
+</pre>
+        <p>stdout &gt;</p>
+        <pre class="programlisting">
+[principal: u1]
+[principal: u2]
+null
+[principal: u3]
+</pre>
+    </div>
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e678"></a>4.4.&nbsp;HTTP authentication and execution context</h2></div></div></div>
+        
+        <p>HttpClient relies on the <code class="classname">AuthState</code> class to keep track of
+            detailed information about the state of the authentication process. HttpClient creates
+            two instances of <code class="classname">AuthState</code> in the course of HTTP request
+            execution: one for target host authentication and another one for proxy authentication.
+            In case the target server or the proxy require user authentication the respective
+                <code class="classname">AuthScope</code> instance will be populated with the
+                <code class="classname">AuthScope</code>, <code class="interfacename">AuthScheme</code> and
+                <code class="interfacename">Crednetials</code> used during the authentication process.
+            The <code class="classname">AuthState</code> can be examined in order to find out what kind of
+            authentication was requested, whether a matching
+                <code class="interfacename">AuthScheme</code> implementation was found and whether the
+            credentials provider managed to find user credentials for the given authentication
+            scope.</p>
+        <p>In the course of HTTP request execution HttpClient adds the following authentication
+            related objects to the execution context:</p>
+        <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
+                <p>
+                    <code class="interfacename">Lookup</code> instance representing the actual
+                        authentication scheme registry. The value of this attribute set in the local
+                        context takes precedence over the default one.
+                </p>
+            </li><li class="listitem">
+                <p>
+                    <code class="interfacename">CredentialsProvider</code> instance representing
+                        the actual credentials provider. The value of this attribute set in the
+                        local context takes precedence over the default one.
+                </p>
+            </li><li class="listitem">
+                <p>
+                    <code class="classname">AuthState</code> instance representing the actual target
+                        authentication state. The value of this attribute set in the local context
+                        takes precedence over the default one.
+                </p>
+            </li><li class="listitem">
+                <p>
+                    <code class="classname">AuthState</code> instance representing the actual proxy
+                        authentication state. The value of this attribute set in the local context
+                        takes precedence over the default one.
+                </p>
+            </li><li class="listitem">
+                <p>
+                    <code class="interfacename">AuthCache</code> instance representing the actual
+                        authentication data cache. The value of this attribute set in the local 
+                        context takes precedence over the default one.
+                </p>
+            </li></ul></div>
+        <p>The local <code class="interfacename">HttpContext</code> object can be used to customize
+            the HTTP authentication context prior to request execution, or to examine its state after
+            the request has been executed:</p>
+        <pre class="programlisting">
+CloseableHttpClient httpclient = &lt;...&gt;
+
+CredentialsProvider credsProvider = &lt;...&gt;
+Lookup&lt;AuthSchemeProvider&gt; authRegistry = &lt;...&gt;
+AuthCache authCache = &lt;...&gt;
+
+HttpClientContext context = HttpClientContext.create();
+context.setCredentialsProvider(credsProvider);
+context.setAuthSchemeRegistry(authRegistry);
+context.setAuthCache(authCache);
+HttpGet httpget = new HttpGet("http://somehost/");
+CloseableHttpResponse response1 = httpclient.execute(httpget, context);
+&lt;...&gt;
+
+AuthState proxyAuthState = context.getProxyAuthState();
+System.out.println("Proxy auth state: " + proxyAuthState.getState());
+System.out.println("Proxy auth scheme: " + proxyAuthState.getAuthScheme());
+System.out.println("Proxy auth credentials: " + proxyAuthState.getCredentials());
+AuthState targetAuthState = context.getTargetAuthState();
+System.out.println("Target auth state: " + targetAuthState.getState());
+System.out.println("Target auth scheme: " + targetAuthState.getAuthScheme());
+System.out.println("Target auth credentials: " + targetAuthState.getCredentials());
+</pre>
+    </div>
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e714"></a>4.5.&nbsp;Caching of authentication data</h2></div></div></div>
+        
+        <p>As of version 4.1 HttpClient automatically caches information about hosts it has 
+            successfully authenticated with. Please note that one must use the same execution 
+            context to execute logically related requests in order for cached authentication data
+            to propagate from one request to another. Authentication data will be lost as soon as 
+            the execution context goes out of scope.</p>
+    </div>
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e717"></a>4.6.&nbsp;Preemptive authentication</h2></div></div></div>
+        
+        <p>HttpClient does not support preemptive authentication out of the box, because if
+            misused or used incorrectly the preemptive authentication can lead to significant
+            security issues, such as sending user credentials in clear text to an unauthorized third
+            party. Therefore, users are expected to evaluate potential benefits of preemptive
+            authentication versus security risks in the context of their specific application
+            environment.</p>
+        <p>Nonetheless one can configure HttpClient to authenticate preemptively by prepopulating
+            the authentication data cache.</p>
+        <pre class="programlisting">
+CloseableHttpClient httpclient = &lt;...&gt;
+
+HttpHost targetHost = new HttpHost("localhost", 80, "http");
+CredentialsProvider credsProvider = new BasicCredentialsProvider();
+credsProvider.setCredentials(
+        new AuthScope(targetHost.getHostName(), targetHost.getPort()),
+        new UsernamePasswordCredentials("username", "password"));
+
+// Create AuthCache instance
+AuthCache authCache = new BasicAuthCache();
+// Generate BASIC scheme object and add it to the local auth cache
+BasicScheme basicAuth = new BasicScheme();
+authCache.put(targetHost, basicAuth);
+
+// Add AuthCache to the execution context
+HttpClientContext context = HttpClientContext.create();
+context.setCredentialsProvider(credsProvider);
+context.setAuthCache(authCache);
+
+HttpGet httpget = new HttpGet("/");
+for (int i = 0; i &lt; 3; i++) {
+    CloseableHttpResponse response = httpclient.execute(
+            targetHost, httpget, context);
+    try {
+        HttpEntity entity = response.getEntity();
+
+    } finally {
+        response.close();
+    }
+}
+</pre>
+    </div>
+
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ntlm"></a>4.7.&nbsp;NTLM Authentication</h2></div></div></div>
+        
+        <p>As of version 4.1 HttpClient provides full support for NTLMv1, NTLMv2, and NTLM2 
+            Session authentication out of the box. One can still continue using an external 
+            <code class="literal">NTLM</code> engine such as <a class="ulink" href="http://jcifs.samba.org/" target="_top">JCIFS
+            </a> library developed by the <a class="ulink" href="http://www.samba.org/" target="_top">Samba</a>
+            project as a part of their Windows interoperability suite of programs.
+        </p>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e728"></a>4.7.1.&nbsp;NTLM connection persistence</h3></div></div></div>
+            
+            <p>The <code class="literal">NTLM</code> authentication scheme is significantly more expensive
+                in terms of computational overhead and performance impact than the standard 
+                <code class="literal">Basic</code> and <code class="literal">Digest</code> schemes. This is likely to be
+                one of the main reasons why Microsoft chose to make <code class="literal">NTLM</code> 
+                authentication scheme stateful. That is, once authenticated, the user identity is 
+                associated with that connection for its entire life span. The stateful nature of 
+                <code class="literal">NTLM</code> connections makes connection persistence more complex, as 
+                for the obvious reason persistent <code class="literal">NTLM</code> connections may not be 
+                re-used by users with a different user identity. The standard connection managers 
+                shipped with HttpClient are fully capable of managing stateful connections. However, 
+                it is critically important that logically related requests within the same session 
+                use the same execution context in order to make them aware of the current user 
+                identity. Otherwise, HttpClient will end up creating a new HTTP connection for each 
+                HTTP request against <code class="literal">NTLM</code> protected resources. For detailed 
+                discussion on stateful HTTP connections please refer to 
+                <a class="link" href="advanced.html#stateful_conn" title="7.2.&nbsp;Stateful HTTP connections">this </a> section. </p>
+                
+            <p>As <code class="literal">NTLM</code> connections are stateful it is generally recommended
+                to trigger <code class="literal">NTLM</code> authentication using a relatively cheap method,
+                such as <code class="literal">GET</code> or <code class="literal">HEAD</code>, and re-use the same 
+                connection to execute more expensive methods, especially those enclose a request
+                entity, such as <code class="literal">POST</code> or <code class="literal">PUT</code>. </p>
+            <pre class="programlisting">
+CloseableHttpClient httpclient = &lt;...&gt;
+
+CredentialsProvider credsProvider = new BasicCredentialsProvider();
+credsProvider.setCredentials(AuthScope.ANY,
+        new NTCredentials("user", "pwd", "myworkstation", "microsoft.com"));
+
+HttpHost target = new HttpHost("www.microsoft.com", 80, "http");
+
+// Make sure the same context is used to execute logically related requests
+HttpClientContext context = HttpClientContext.create();
+context.setCredentialsProvider(credsProvider);
+
+// Execute a cheap method first. This will trigger NTLM authentication
+HttpGet httpget = new HttpGet("/ntlm-protected/info");
+CloseableHttpResponse response1 = httpclient.execute(target, httpget, context);
+try {
+    HttpEntity entity1 = response1.getEntity();
+} finally {
+    response1.close();
+}
+
+// Execute an expensive method next reusing the same context (and connection)
+HttpPost httppost = new HttpPost("/ntlm-protected/form");
+httppost.setEntity(new StringEntity("lots and lots of data"));
+CloseableHttpResponse response2 = httpclient.execute(target, httppost, context);
+try {
+    HttpEntity entity2 = response2.getEntity();
+} finally {
+    response2.close();
+}
+</pre>
+        </div>
+    </div>
+
+    <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="spnego"></a>4.8.&nbsp;<code class="literal">SPNEGO</code>/Kerberos Authentication</h2></div></div></div>
+        
+        <p>The <code class="literal">SPNEGO</code> (<span class="emphasis"><em>S</em></span>imple and
+            <span class="emphasis"><em>P</em></span>rotected <code class="literal">GSSAPI</code>
+            <span class="emphasis"><em>Nego</em></span>tiation Mechanism) is designed to allow for authentication to
+            services when neither end knows what the other can use/provide. It is most commonly used
+            to do Kerberos authentication. It can wrap other mechanisms, however the current version
+            in HttpClient is designed solely with Kerberos in mind. </p>
+        <div class="sidebar"><div class="titlepage"><div><div><p class="title"><b></b></p></div></div></div>
+            <div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
+                    <p>Client Web Browser does HTTP GET for resource.</p>
+                </li><li class="listitem">
+                    <p>Web server returns HTTP 401 status and a header:
+                            <code class="literal">WWW-Authenticate: Negotiate</code></p>
+                </li><li class="listitem">
+                    <p>Client generates a <code class="literal">NegTokenInit</code>, base64 encodes it, and
+                        resubmits the <code class="literal">GET</code> with an Authorization header:
+                            <code class="literal">Authorization: Negotiate &lt;base64
+                            encoding&gt;</code>.</p>
+                </li><li class="listitem">
+                    <p>Server decodes the <code class="literal">NegTokenInit</code>, extracts the supported
+                            <code class="literal">MechTypes</code> (only Kerberos V5 in our case), ensures it
+                        is one of the expected ones, and then extracts the
+                            <code class="literal">MechToken</code> (Kerberos Token) and authenticates
+                        it.</p>
+                    <p>If more processing is required another HTTP 401 is returned to the client
+                        with more data in the the <code class="literal">WWW-Authenticate</code> header. Client
+                        takes the info and generates another token passing this back in the
+                            <code class="literal">Authorization</code> header until complete.</p>
+                </li><li class="listitem">
+                    <p>When the client has been authenticated the Web server should return the
+                        HTTP 200 status, a final <code class="literal">WWW-Authenticate</code> header and the
+                        page content.</p>
+                </li></ol></div>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e779"></a>4.8.1.&nbsp;<code class="literal">SPNEGO</code> support in HttpClient</h3></div></div></div>
+            
+            <p>The <code class="literal">SPNEGO</code> authentication scheme is compatible with Sun Java
+                versions 1.5 and up. However the use of Java &gt;= 1.6 is strongly recommended as it 
+                supports <code class="literal">SPNEGO</code> authentication more completely.</p>
+            <p>The Sun JRE provides the supporting classes to do nearly all the Kerberos and
+                    <code class="literal">SPNEGO</code> token handling. This means that a lot of the setup is
+                for the GSS classes. The <code class="classname">SPNegoScheme</code> is a simple class to
+                handle marshalling the tokens and reading and writing the correct headers.</p>
+            <p>The best way to start is to grab the <code class="literal">KerberosHttpClient.java</code>
+                file in examples and try and get it to work. There are a lot of issues that can
+                happen but if lucky it'll work without too much of a problem. It should also provide some
+                output to debug with.</p>
+
+            <p>In Windows it should default to using the logged in credentials; this can be
+                overridden by using 'kinit' e.g. <code class="literal">$JAVA_HOME\bin\kinit
+                    testuser@AD.EXAMPLE.NET</code>, which is very helpful for testing and
+                debugging issues. Remove the cache file created by kinit to revert back to the windows
+                Kerberos cache.</p>
+            <p>Make sure to list <code class="literal">domain_realms</code> in the
+                    <code class="literal">krb5.conf</code> file. This is a major source of problems.</p>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e795"></a>4.8.2.&nbsp;GSS/Java Kerberos Setup</h3></div></div></div>
+            
+            <p>This documentation assumes you are using Windows but much of the information
+                applies to Unix as well.</p>
+            <p>The <code class="classname">org.ietf.jgss</code> classes have lots of possible
+                configuration parameters, mainly in the
+                    <code class="literal">krb5.conf</code>/<code class="literal">krb5.ini</code> file. Some more info on
+                the format at <a class="ulink" href="http://web.mit.edu/kerberos/krb5-1.4/krb5-1.4.1/doc/krb5-admin/krb5.conf.html" target="_top">http://web.mit.edu/kerberos/krb5-1.4/krb5-1.4.1/doc/krb5-admin/krb5.conf.html</a>.</p>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e803"></a>4.8.3.&nbsp;<code class="literal">login.conf</code> file</h3></div></div></div>
+            
+            <p>The following configuration is a basic setup that works in Windows XP against both
+                    <code class="literal">IIS</code> and <code class="literal">JBoss Negotiation</code> modules.</p>
+            <p>The system property <code class="literal">java.security.auth.login.config</code> can be used
+                to point at the <code class="literal">login.conf</code> file.</p>
+            <p><code class="literal">login.conf</code> content may look like the following:</p>
+            <pre class="programlisting">
+com.sun.security.jgss.login {
+  com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true;
+};
+
+com.sun.security.jgss.initiate {
+  com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true;
+};
+
+com.sun.security.jgss.accept {
+  com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true;
+};
+
+</pre>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e815"></a>4.8.4.&nbsp;<code class="literal">krb5.conf</code> / <code class="literal">krb5.ini</code> file</h3></div></div></div>
+            
+            <p>If unspecified, the system default will be used. Override if needed by setting the
+                system property <code class="literal">java.security.krb5.conf</code> to point to a custom
+                    <code class="literal">krb5.conf</code> file.</p>
+            <p><code class="literal">krb5.conf</code> content may look like the following:</p>
+            <pre class="programlisting">
+[libdefaults]
+    default_realm = AD.EXAMPLE.NET
+    udp_preference_limit = 1
+[realms]
+    AD.EXAMPLE.NET = {
+        kdc = KDC.AD.EXAMPLE.NET
+    }
+[domain_realms]
+.ad.example.net=AD.EXAMPLE.NET
+ad.example.net=AD.EXAMPLE.NET
+
+</pre>
+        </div>
+        <div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d5e825"></a>4.8.5.&nbsp;Windows Specific configuration</h3></div></div></div>
+            
+            <p>To allow Windows to use the current user's tickets, the system property
+                    <code class="literal">javax.security.auth.useSubjectCredsOnly</code> must be set to
+                    <code class="literal">false</code> and the Windows registry key
+                    <code class="literal">allowtgtsessionkey</code> should be added and set correctly to allow
+                session keys to be sent in the Kerberos Ticket-Granting Ticket.</p>
+            <p>On the Windows Server 2003 and Windows 2000 SP4, here is the required registry
+                setting:</p>
+            <pre class="programlisting">
+HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters
+Value Name: allowtgtsessionkey
+Value Type: REG_DWORD
+Value: 0x01
+
+            </pre>
+            <p>Here is the location of the registry setting on Windows XP SP2:</p>
+            <pre class="programlisting">
+HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\
+Value Name: allowtgtsessionkey
+Value Type: REG_DWORD
+Value: 0x01
+
+            </pre>
+        </div>
+    </div>
+
+</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="statemgmt.html">Prev</a>&nbsp;</td><td width="20%" align="center">&nbsp;</td><td width="40%" align="right">&nbsp;<a accesskey="n" href="fluent.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;3.&nbsp;HTTP state management&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Chapter&nbsp;5.&nbsp;Fluent API</td></tr></table></div></body></html>
\ No newline at end of file

Added: httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/caching.html
URL: http://svn.apache.org/viewvc/httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/caching.html?rev=1907880&view=auto
==============================================================================
--- httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/caching.html (added)
+++ httpcomponents/site/components/httpcomponents-client-4.5.x/4.5.14/tutorial/html/caching.html Sun Feb 26 16:12:58 2023
@@ -0,0 +1,211 @@
+<html><head>
+      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+   <title>Chapter&nbsp;6.&nbsp;HTTP Caching</title><link rel="stylesheet" type="text/css" href="css/hc-tutorial.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="index.html" title="HttpClient Tutorial"><link rel="up" href="index.html" title="HttpClient Tutorial"><link rel="prev" href="fluent.html" title="Chapter&nbsp;5.&nbsp;Fluent API"><link rel="next" href="advanced.html" title="Chapter&nbsp;7.&nbsp;Advanced topics"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div xmlns:fo="http://www.w3.org/1999/XSL/Format" class="banner"><a class="bannerLeft" href="http://www.apache.org/" title="Apache Software Foundation"><img style="border:none;" src="images/asf_logo_wide.gif"></a><a class="bannerRight" href="http://hc.apache.org/httpcomponents-client-ga/" title="Apache HttpComponents Client"><img style="border:none;" src="images/hc_logo.png"></a><div class="clear"></div></div><div class="navheader"><table 
 width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;6.&nbsp;HTTP Caching</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="fluent.html">Prev</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="advanced.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="caching"></a>Chapter&nbsp;6.&nbsp;HTTP Caching</h1></div></div></div>
+  
+
+  <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="generalconcepts"></a>6.1.&nbsp;General Concepts</h2></div></div></div>
+    
+
+    <p>HttpClient Cache provides an HTTP/1.1-compliant caching layer to be
+    used with HttpClient--the Java equivalent of a browser cache. The
+    implementation follows the Chain of Responsibility design pattern, where the
+    caching HttpClient implementation can serve a drop-in replacement for
+    the default non-caching HttpClient implementation; requests that can be
+    satisfied entirely from the cache will not result in actual origin requests.
+    Stale cache entries are automatically validated with the origin where possible,
+    using conditional GETs and the If-Modified-Since and/or If-None-Match request
+    headers.
+    </p>
+    
+    <p>
+    HTTP/1.1 caching in general is designed to be <span class="emphasis"><em>semantically
+    transparent</em></span>; that is, a cache should not change the meaning of 
+    the request-response exchange between client and server. As such, it should
+    be safe to drop a caching HttpClient into an existing compliant client-server
+    relationship. Although the caching module is part of the client from an
+    HTTP protocol point of view, the implementation aims to be compatible with
+    the requirements placed on a transparent caching proxy.
+    </p>
+    
+    <p>Finally, caching HttpClient includes support the Cache-Control
+    extensions specified by RFC 5861 (stale-if-error and stale-while-revalidate).
+    </p>
+
+    <p>When caching HttpClient executes a request, it goes through the
+    following flow:</p>
+
+    <div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
+        <p>Check the request for basic compliance with the HTTP 1.1
+        protocol and attempt to correct the request.</p>
+      </li><li class="listitem">
+        <p>Flush any cache entries which would be invalidated by this
+        request.</p>
+      </li><li class="listitem">
+        <p>Determine if the current request would be servable from cache.
+        If not, directly pass through the request to the origin server and
+        return the response, after caching it if appropriate.</p>
+      </li><li class="listitem">
+        <p>If it was a a cache-servable request, it will attempt to read it
+        from the cache. If it is not in the cache, call the origin server and
+        cache the response, if appropriate.</p>
+      </li><li class="listitem">
+        <p>If the cached response is suitable to be served as a response,
+        construct a BasicHttpResponse containing a ByteArrayEntity and return
+        it. Otherwise, attempt to revalidate the cache entry against the
+        origin server.</p>
+      </li><li class="listitem">
+        <p>In the case of a cached response which cannot be revalidated,
+        call the origin server and cache the response, if appropriate.</p>
+      </li></ol></div>
+
+    <p>When caching HttpClient receives a response, it goes through the
+    following flow:</p>
+
+    <div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
+        <p>Examining the response for protocol compliance</p>
+      </li><li class="listitem">
+        <p>Determine whether the response is cacheable</p>
+      </li><li class="listitem">
+        <p>If it is cacheable, attempt to read up to the maximum size
+        allowed in the configuration and store it in the cache.</p>
+      </li><li class="listitem">
+        <p>If the response is too large for the cache, reconstruct the
+        partially consumed response and return it directly without caching
+        it.</p>
+      </li></ol></div>
+
+    <p>It is important to note that caching HttpClient is not, itself,
+    a different implementation of HttpClient, but that it works by inserting
+    itself as an additonal processing component to the request execution
+    pipeline.</p>
+  </div>
+
+  <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="rfc2616compliance"></a>6.2.&nbsp;RFC-2616 Compliance</h2></div></div></div>
+    
+
+    <p>We believe HttpClient Cache is <span class="emphasis"><em>unconditionally
+    compliant</em></span> with <a class="ulink" href="http://www.ietf.org/rfc/rfc2616.txt" target="_top">RFC-2616</a>. That is,
+    wherever the specification indicates MUST, MUST NOT, SHOULD, or SHOULD NOT
+    for HTTP caches, the caching layer attempts to behave in a way that satisfies
+    those requirements. This means the caching module won't produce incorrect
+    behavior when you drop it in. </p>
+  </div>
+
+  <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d5e890"></a>6.3.&nbsp;Example Usage</h2></div></div></div>
+    
+
+    <p>This is a simple example of how to set up a basic caching HttpClient.
+    As configured, it will store a maximum of 1000 cached objects, each of
+    which may have a maximum body size of 8192 bytes. The numbers selected
+    here are for example only and not intended to be prescriptive or
+    considered as recommendations.</p>
+
+    <pre class="programlisting">
+CacheConfig cacheConfig = CacheConfig.custom()
+        .setMaxCacheEntries(1000)
+        .setMaxObjectSize(8192)
+        .build();
+RequestConfig requestConfig = RequestConfig.custom()
+        .setConnectTimeout(30000)
+        .setSocketTimeout(30000)
+        .build();
+CloseableHttpClient cachingClient = CachingHttpClients.custom()
+        .setCacheConfig(cacheConfig)
+        .setDefaultRequestConfig(requestConfig)
+        .build();
+
+HttpCacheContext context = HttpCacheContext.create();
+HttpGet httpget = new HttpGet("http://www.mydomain.com/content/");
+CloseableHttpResponse response = cachingClient.execute(httpget, context);
+try {
+    CacheResponseStatus responseStatus = context.getCacheResponseStatus();
+    switch (responseStatus) {
+        case CACHE_HIT:
+            System.out.println("A response was generated from the cache with " +
+                    "no requests sent upstream");
+            break;
+        case CACHE_MODULE_RESPONSE:
+            System.out.println("The response was generated directly by the " +
+                    "caching module");
+            break;
+        case CACHE_MISS:
+            System.out.println("The response came from an upstream server");
+            break;
+        case VALIDATED:
+            System.out.println("The response was generated from the cache " +
+                    "after validating the entry with the origin server");
+            break;
+    }
+} finally {
+    response.close();
+}
+
+    </pre>
+  </div>
+  
+  <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="configuration"></a>6.4.&nbsp;Configuration</h2></div></div></div>
+    
+
+    <p>The caching HttpClient inherits all configuration options and parameters
+    of the default non-caching implementation (this includes setting options like
+    timeouts and connection pool sizes). For caching-specific configuration, you can
+    provide a <code class="classname">CacheConfig</code> instance to customize behavior
+    across the following areas:</p>
+    
+    <p><span class="emphasis"><em>Cache size.</em></span> If the backend storage supports these limits,
+    you can specify the maximum number of cache entries as well as the maximum cacheable
+    response body size.</p>
+    
+
+    <p><span class="emphasis"><em>Public/private caching.</em></span> By default, the caching module
+    considers itself to be a shared (public) cache, and will not, for example, cache
+    responses to requests with Authorization headers or responses marked with
+    "Cache-Control: private". If, however, the cache is only going to be used by one
+    logical "user" (behaving similarly to a browser cache), then you will want to turn
+    off the shared cache setting.</p>
+
+    <p><span class="emphasis"><em>Heuristic caching.</em></span>Per RFC2616, a cache MAY cache
+    certain cache entries even if no explicit cache control headers are set by the
+    origin. This behavior is off by default, but you may want to turn this on if you
+    are working with an origin that doesn't set proper headers but where you still
+    want to cache the responses. You will want to enable heuristic caching, then
+    specify either a default freshness lifetime and/or a fraction of the time since
+    the resource was last modified. See Sections 13.2.2 and 13.2.4 of the HTTP/1.1
+    RFC for more details on heuristic caching.</p>
+
+    <p><span class="emphasis"><em>Background validation.</em></span> The cache module supports the
+    stale-while-revalidate directive of RFC5861, which allows certain cache entry
+    revalidations to happen in the background. You may want to tweak the settings
+    for the minimum and maximum number of background worker threads, as well as the
+    maximum time they can be idle before being reclaimed. You can also control the
+    size of the queue used for revalidations when there aren't enough workers to
+    keep up with demand.</p>
+  </div>
+  
+  <div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="storage"></a>6.5.&nbsp;Storage Backends</h2></div></div></div>
+    
+
+    <p>The default implementation of caching HttpClient stores cache entries and
+    cached response bodies in memory in the JVM of your application. While this
+    offers high performance, it may not be appropriate for your application due to
+    the limitation on size or because the cache entries are ephemeral and don't
+    survive an application restart. The current release includes support for storing
+    cache entries using EhCache and memcached implementations, which allow for
+    spilling cache entries to disk or storing them in an external process.</p>
+    
+    <p>If none of those options are suitable for your application, it is
+    possible to provide your own storage backend by implementing the HttpCacheStorage
+    interface and then supplying that to caching HttpClient at construction time. In
+    this case, the cache entries will be stored using your scheme but you will get to
+    reuse all of the logic surrounding HTTP/1.1 compliance and cache handling.
+    Generally speaking, it should be possible to create an HttpCacheStorage
+    implementation out of anything that supports a key/value store (similar to the
+    Java Map interface) with the ability to apply atomic updates.</p>
+    
+    <p>Finally, with some extra efforts it's entirely possible to set up
+    a multi-tier caching hierarchy; for example, wrapping an in-memory caching
+    HttpClient around one that stores cache entries on disk or remotely in memcached,
+    following a pattern similar to virtual memory, L1/L2 processor caches, etc.
+    </p>
+  </div>
+</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="fluent.html">Prev</a>&nbsp;</td><td width="20%" align="center">&nbsp;</td><td width="40%" align="right">&nbsp;<a accesskey="n" href="advanced.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;5.&nbsp;Fluent API&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Chapter&nbsp;7.&nbsp;Advanced topics</td></tr></table></div></body></html>
\ No newline at end of file