Search in sources :

Example 6 with CookieSpec

use of org.apache.http.cookie.CookieSpec in project platform_external_apache-http by android.

the class ResponseProcessCookies method process.

public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    // Obtain cookie store
    CookieStore cookieStore = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
    if (cookieStore == null) {
        this.log.info("Cookie store not available in HTTP context");
        return;
    }
    // Obtain actual CookieSpec instance
    CookieSpec cookieSpec = (CookieSpec) context.getAttribute(ClientContext.COOKIE_SPEC);
    if (cookieSpec == null) {
        this.log.info("CookieSpec not available in HTTP context");
        return;
    }
    // Obtain actual CookieOrigin instance
    CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(ClientContext.COOKIE_ORIGIN);
    if (cookieOrigin == null) {
        this.log.info("CookieOrigin not available in HTTP context");
        return;
    }
    HeaderIterator it = response.headerIterator(SM.SET_COOKIE);
    processCookies(it, cookieSpec, cookieOrigin, cookieStore);
    // see if the cookie spec supports cookie versioning.
    if (cookieSpec.getVersion() > 0) {
        // process set-cookie2 headers.
        // Cookie2 will replace equivalent Cookie instances
        it = response.headerIterator(SM.SET_COOKIE2);
        processCookies(it, cookieSpec, cookieOrigin, cookieStore);
    }
}
Also used : CookieStore(org.apache.http.client.CookieStore) CookieSpec(org.apache.http.cookie.CookieSpec) HeaderIterator(org.apache.http.HeaderIterator) CookieOrigin(org.apache.http.cookie.CookieOrigin)

Aggregations

CookieStore (org.apache.http.client.CookieStore)6 CookieOrigin (org.apache.http.cookie.CookieOrigin)6 CookieSpec (org.apache.http.cookie.CookieSpec)6 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3 Header (org.apache.http.Header)3 HeaderIterator (org.apache.http.HeaderIterator)3 HttpHost (org.apache.http.HttpHost)3 ProtocolException (org.apache.http.ProtocolException)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 ManagedClientConnection (org.apache.http.conn.ManagedClientConnection)3 Cookie (org.apache.http.cookie.Cookie)3 CookieSpecRegistry (org.apache.http.cookie.CookieSpecRegistry)3