Code example for BasicHttpRequest

Methods: addHeadergetFirstHeader

0
        Assert.assertNull(header2);
    } 
 
    @Test 
    public void testPreserveCustomConnectionHeader() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        HttpContext context = new BasicHttpContext();
 
        HttpHost target = new HttpHost("localhost", 443, "https");
        HttpHost proxy = new HttpHost("localhost", 8080);
        HttpRoute route = new HttpRoute(target, null, proxy, true,
                TunnelType.TUNNELLED, LayerType.LAYERED);
 
        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
 
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
 
        HttpRequestInterceptor interceptor = new RequestClientConnControl();
        interceptor.process(request, context);
 
        Header header1 = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
        Assert.assertNotNull(header1);
        Assert.assertEquals(HTTP.CONN_CLOSE, header1.getValue());
        Header header2 = request.getFirstHeader("Proxy-Connection");
        Assert.assertNull(header2);
    } 
 
    @Test 
    public void testPreserveCustomProxyConnectionHeader() throws Exception { 
Experience pair programming with AI  Get Codota for Java