Package org.apache.http

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


    }

    public void testInvalidContentLength() throws Exception {
        // Use HTTP 1.1
        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.addHeader("Content-Length", "crap");
        assertFalse(reuseStrategy.keepAlive(response, context));
    }

    public void testInvalidNegativeContentLength() throws Exception {
        // Use HTTP 1.1
View Full Code Here


    }

    public void testInvalidNegativeContentLength() throws Exception {
        // Use HTTP 1.1
        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.addHeader("Content-Length", "-10");
        assertFalse(reuseStrategy.keepAlive(response, context));
    }

}
View Full Code Here

            try {
                return revalidateCacheEntry(target, request, context, entry);
            } catch (IOException ioex) {
                HttpResponse response = responseGenerator.generateResponse(entry);
                response.addHeader(HeaderConstants.WARNING, "111 Revalidation Failed - " + ioex.getMessage());
                log.debug("111 revalidation failed due to exception: " + ioex);
                return response;
            } catch (ProtocolException e) {
                throw new ClientProtocolException(e);
            }
View Full Code Here

            String oldVal, String newVal) throws Exception {

        // put something cacheable in the cache
        HttpRequest req1 = new BasicHttpRequest("GET", "/", HTTP_1_1);
        HttpResponse resp1 = make200Response();
        resp1.addHeader("Cache-Control", "max-age=3600");
        resp1.setHeader(eHeader, oldVal);

        // get a head that penetrates the cache
        HttpRequest req2 = new BasicHttpRequest("HEAD", "/", HTTP_1_1);
        req2.addHeader("Cache-Control", "no-cache");
View Full Code Here

     */
    @Test
    public void testMultiHeadersAreSuccessfullyReplacedOn304Validation() throws Exception {
        HttpRequest req1 = new BasicHttpRequest("GET", "/", HTTP_1_1);
        HttpResponse resp1 = make200Response();
        resp1.addHeader("Cache-Control","max-age=3600");
        resp1.addHeader("Cache-Control","public");
        resp1.setHeader("ETag","\"etag\"");

        HttpRequest req2 = new BasicHttpRequest("GET", "/", HTTP_1_1);
        req2.setHeader("Cache-Control", "max-age=0, max-stale=0");
View Full Code Here

    @Test
    public void testMultiHeadersAreSuccessfullyReplacedOn304Validation() throws Exception {
        HttpRequest req1 = new BasicHttpRequest("GET", "/", HTTP_1_1);
        HttpResponse resp1 = make200Response();
        resp1.addHeader("Cache-Control","max-age=3600");
        resp1.addHeader("Cache-Control","public");
        resp1.setHeader("ETag","\"etag\"");

        HttpRequest req2 = new BasicHttpRequest("GET", "/", HTTP_1_1);
        req2.setHeader("Cache-Control", "max-age=0, max-stale=0");
        HttpResponse resp2 = new BasicHttpResponse(HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified");
View Full Code Here

    public void testEmptyKeepAliveHeader() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        HttpResponse response = new BasicHttpResponse(
                new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
        response.addHeader("Keep-Alive", "timeout, max=20");
        ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
        long d = keepAliveStrat.getKeepAliveDuration(response, context);
        assertEquals(-1, d);
    }
View Full Code Here

    public void testInvalidKeepAliveHeader() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        HttpResponse response = new BasicHttpResponse(
                new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
        response.addHeader("Keep-Alive", "timeout=whatever, max=20");
        ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
        long d = keepAliveStrat.getKeepAliveDuration(response, context);
        assertEquals(-1, d);
    }
View Full Code Here

    public void testKeepAliveHeader() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        HttpResponse response = new BasicHttpResponse(
                new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
        response.addHeader("Keep-Alive", "timeout=300, max=20");
        ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
        long d = keepAliveStrat.getKeepAliveDuration(response, context);
        assertEquals(300000, d);
    }
View Full Code Here

    @Test
    public void testMultiHeadersAreSuccessfullyReplacedOn304Validation() throws Exception {
        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        final HttpResponse resp1 = HttpTestUtils.make200Response();
        resp1.addHeader("Cache-Control","max-age=3600");
        resp1.addHeader("Cache-Control","public");
        resp1.setHeader("ETag","\"etag\"");

        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
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.