Package org.apache.http

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


            // Needs to be done after execute to pick up all the headers
            final HttpRequest request = (HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST);
            // We've finished with the request, so we can add the LocalAddress to it for display
            final InetAddress localAddr = (InetAddress) httpRequest.getParams().getParameter(ConnRoutePNames.LOCAL_ADDRESS);
            if (localAddr != null) {
                request.addHeader(HEADER_LOCAL_ADDRESS, localAddr.toString());
            }
            res.setRequestHeaders(getConnectionHeaders(request));

            Header contentType = httpResponse.getLastHeader(HTTPConstants.HEADER_CONTENT_TYPE);
            if (contentType != null){
View Full Code Here


  }
 
  @Test
  public void testGetHeader() {
    HttpRequest request = new BasicHttpRequest("GET", "/test.html");
    request.addHeader("id", "test");
    request.addHeader("test", "");
    assertEquals("test", HeaderUtils.getHeader(request, "id"));
    assertEquals("", HeaderUtils.getHeader(request, "test"));
    assertEquals(null, HeaderUtils.getHeader(request, "abc"));
   
View Full Code Here

 
  @Test
  public void testGetHeader() {
    HttpRequest request = new BasicHttpRequest("GET", "/test.html");
    request.addHeader("id", "test");
    request.addHeader("test", "");
    assertEquals("test", HeaderUtils.getHeader(request, "id"));
    assertEquals("", HeaderUtils.getHeader(request, "test"));
    assertEquals(null, HeaderUtils.getHeader(request, "abc"));
   
    assertEquals("default", HeaderUtils.getHeader(request, "abc", "default"));
View Full Code Here

        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        // First request : retrieve a domain cookie from remote server.
        URI uri = new URI("http://app.mydomain.fr");
        HttpRequest httpRequest = new HttpGet(uri);
        httpRequest.addHeader("X-Request", "1");
        final HttpResponse response1 = this.httpclient.execute(getServerHttp(),
                httpRequest, context);
        final HttpEntity e1 = response1.getEntity();
        EntityUtils.consume(e1);
View Full Code Here

        Assert.assertEquals("name1", cookies.get(0).getName());

        // Second request : send the cookie back.
        uri = new URI("http://app.mydomain.fr");
        httpRequest = new HttpGet(uri);
        httpRequest.addHeader("X-Request", "2");
        final HttpResponse response2 = this.httpclient.execute(getServerHttp(),
                httpRequest, context);
        final HttpEntity e2 = response2.getEntity();
        EntityUtils.consume(e2);
View Full Code Here

        EntityUtils.consume(e2);

        // Third request : Host header
        uri = new URI("http://app.mydomain.fr");
        httpRequest = new HttpGet(uri);
        httpRequest.addHeader("X-Request", "3");
        final HttpResponse response3 = this.httpclient.execute(getServerHttp(),
                httpRequest, context);
        final HttpEntity e3 = response3.getEntity();
        EntityUtils.consume(e3);
    }
View Full Code Here

    }

    @Test
    public void testPreserveCustomConnectionHeader() throws Exception {
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        final HttpContext context = new BasicHttpContext();

        final HttpHost target = new HttpHost("localhost", 443, "https");
        final HttpHost proxy = new HttpHost("localhost", 8080);
        final HttpRoute route = new HttpRoute(target, null, proxy, true,
View Full Code Here

    }

    @Test
    public void testPreserveCustomProxyConnectionHeader() throws Exception {
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader("Proxy-Connection", HTTP.CONN_CLOSE);
        final HttpContext context = new BasicHttpContext();

        final HttpHost target = new HttpHost("localhost", 80, "http");
        final HttpHost proxy = new HttpHost("localhost", 8080);
        final HttpRoute route = new HttpRoute(target, null, proxy, false,
View Full Code Here

    }

    @Test
    public void testAcceptEncodingAlreadyPResent() throws Exception {
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader("Accept-Encoding", "stuff");
        final HttpContext context = new BasicHttpContext();

        final HttpRequestInterceptor interceptor = new RequestAcceptEncoding();
        interceptor.process(request, context);
        final Header header = request.getFirstHeader("Accept-Encoding");
View Full Code Here

    }

    @Test
    public void testDefaultHeaders() throws Exception {
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader("custom", "stuff");
        final List<Header> defheaders = new ArrayList<Header>();
        defheaders.add(new BasicHeader("custom", "more stuff"));
        final HttpContext context = new BasicHttpContext();

        final HttpRequestInterceptor interceptor = new RequestDefaultHeaders(defheaders);
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.