Package org.apache.http

Examples of org.apache.http.HttpResponse.addHeader()


            if (this.asynchAsyncRevalidator != null
                && !staleResponseNotAllowed(request, entry, now)
                && this.validityPolicy.mayReturnStaleWhileRevalidating(entry, now)) {
                this.log.debug("Serving stale with asynchronous revalidation");
                final HttpResponse resp = this.responseGenerator.generateResponse(entry);
                resp.addHeader(HeaderConstants.WARNING, "110 localhost \"Response is stale\"");

                this.asynchAsyncRevalidator.revalidateCacheEntry(target, request, clientContext, entry);

                future.completed(resp);
                return;
View Full Code Here


        } else {
            cachedResponse = this.responseGenerator.generateResponse(entry);
        }
        setResponseStatus(clientContext, CacheResponseStatus.CACHE_HIT);
        if (this.validityPolicy.getStalenessSecs(entry, now) > 0L) {
            cachedResponse.addHeader("Warning","110 localhost \"Response is stale\"");
        }
        return cachedResponse;
    }

    private HttpResponse handleRevalidationFailure(
View Full Code Here

    private HttpResponse unvalidatedCacheHit(
            final HttpCacheContext clientContext,
            final HttpCacheEntry entry) {
        final HttpResponse cachedResponse = this.responseGenerator.generateResponse(entry);
        setResponseStatus(clientContext, CacheResponseStatus.CACHE_HIT);
        cachedResponse.addHeader(HeaderConstants.WARNING, "111 localhost \"Revalidation failed\"");
        return cachedResponse;
    }

    private boolean staleResponseNotAllowed(
            final HttpRequest request,
View Full Code Here

        if (staleIfErrorAppliesTo(statusCode)
            && !staleResponseNotAllowed(request, cacheEntry, getCurrentDate())
            && CachingHttpAsyncClient.this.validityPolicy.mayReturnStaleIfError(request, cacheEntry, responseDate)) {
            final HttpResponse cachedResponse = CachingHttpAsyncClient.this.responseGenerator.generateResponse(cacheEntry);
            cachedResponse.addHeader(HeaderConstants.WARNING, "110 localhost \"Response is stale\"");
            future.completed(cachedResponse);
            return;
        }

        try {
View Full Code Here

    public void testResponseContentInvalidResponseState() throws Exception {
        ResponseContent interceptor = new ResponseContent();
        HttpContext context = new BasicHttpContext(null);
        try {
            HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
            response.addHeader(new BasicHeader(HTTP.CONTENT_LEN, "10"));
            interceptor.process(response, context);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
            // expected
        }
View Full Code Here

        } catch (ProtocolException ex) {
            // expected
        }
        try {
            HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
            response.addHeader(new BasicHeader(HTTP.TRANSFER_ENCODING, "stuff"));
            interceptor.process(response, context);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
            // expected
        }
View Full Code Here

    public void testResponseServerNotGenerated() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        response.getParams().setParameter(CoreProtocolPNames.ORIGIN_SERVER, "some server");
        response.addHeader(new BasicHeader(HTTP.SERVER_HEADER, "whatever"));
        ResponseServer interceptor = new ResponseServer();
        interceptor.process(response, context);
        Header h1 = response.getFirstHeader(HTTP.SERVER_HEADER);
        assertNotNull(h1);
        assertEquals("whatever", h1.getValue());
View Full Code Here

    public void testResponseContentInvalidResponseState() throws Exception {
        ResponseContent interceptor = new ResponseContent();
        HttpContext context = new HttpExecutionContext(null);
        try {
            HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
            response.addHeader(new BasicHeader(HTTP.CONTENT_LEN, "10"));
            interceptor.process(response, context);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
            // expected
        }
View Full Code Here

        } catch (ProtocolException ex) {
            // expected
        }
        try {
            HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
            response.addHeader(new BasicHeader(HTTP.TRANSFER_ENCODING, "stuff"));
            interceptor.process(response, context);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
            // expected
        }
View Full Code Here

       
    public void testResponseServerNotGenerated() throws Exception {
        HttpContext context = new HttpExecutionContext(null);
        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        response.getParams().setParameter(HttpProtocolParams.ORIGIN_SERVER, "some server");
        response.addHeader(new BasicHeader(HTTP.SERVER_DIRECTIVE, "whatever"));
        ResponseServer interceptor = new ResponseServer();
        interceptor.process(response, context);
        Header h1 = response.getFirstHeader(HTTP.SERVER_DIRECTIVE);
        assertNotNull(h1);
        assertEquals("whatever", h1.getValue());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.