Package org.apache.http.message

Examples of org.apache.http.message.BasicHttpResponse.addHeader()


    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

    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

    public void testMultipleAllows() {
        ProtocolVersion proto = new ProtocolVersion("HTTP", 1, 1);
        BasicStatusLine line = new BasicStatusLine(proto, 200, "test reason");
        BasicHttpResponse resp = new BasicHttpResponse(line);
        resp.addHeader("Allow", "POST");
        resp.addHeader("Allow", "GET");

        HttpOptions opt = new HttpOptions();
        Set<String> methodsName = opt.getAllowedMethods(resp);
       
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.