Package org.apache.http

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


    public void testConnectionTokens5() throws Exception {
        // Use HTTP 1.1
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);
        response.addHeader("Connection", "yadda, dumdy");
        response.addHeader("Proxy-Connection", "close");

        // Connection takes precedence over Proxy-Connection,
        // even if it doesn't contain a recognized token.
        // Default for HTTP/1.1 is to keep alive.
View Full Code Here


    public void testConnectionTokens5() throws Exception {
        // Use HTTP 1.1
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);
        response.addHeader("Connection", "yadda, dumdy");
        response.addHeader("Proxy-Connection", "close");

        // Connection takes precedence over Proxy-Connection,
        // even if it doesn't contain a recognized token.
        // Default for HTTP/1.1 is to keep alive.
        assertTrue(reuseStrategy.keepAlive(response, context));
View Full Code Here

    public void testConnectionTokens6() throws Exception {
        // Use HTTP 1.1
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);
        response.addHeader("Connection", "");
        response.addHeader("Proxy-Connection", "close");

        // Connection takes precedence over Proxy-Connection,
        // even if it is empty. Default for HTTP/1.1 is to keep alive.
        assertTrue(reuseStrategy.keepAlive(response, context));
View Full Code Here

    public void testConnectionTokens6() throws Exception {
        // Use HTTP 1.1
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);
        response.addHeader("Connection", "");
        response.addHeader("Proxy-Connection", "close");

        // Connection takes precedence over Proxy-Connection,
        // even if it is empty. Default for HTTP/1.1 is to keep alive.
        assertTrue(reuseStrategy.keepAlive(response, context));
    }
View Full Code Here

    public void testConnectionTokensInvalid() throws Exception {
        // Use HTTP 1.1
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);
        response.addHeader("Connection", "keep-alive=true");

        assertFalse(reuseStrategy.keepAlive(response, context));
    }

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

            try {
                HttpResponse response = this.responseFactory.newHttpResponse(
                        HttpVersion.HTTP_1_0, HttpStatus.SC_BAD_REQUEST, context);
                response.setParams(this.params);
                response.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
                // Pre-process HTTP request
                context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
                context.setAttribute(ExecutionContext.HTTP_REQUEST, null);
                this.httpProcessor.process(response, context);
               
View Full Code Here

        BasicHttpEntity entity = new BasicHttpEntity();
        entity.setChunked(false);
        entity.setContentLength(-1);
        StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_0, 200, "OK");
        HttpResponse response = new BasicHttpResponse(statusline);
        response.addHeader(new Header("Connection", "keep-alive"));
        response.setEntity(entity);

        ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
        assertFalse(s.keepAlive(response));
    }
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.