Code example for BasicHttpRequest

Methods: addHeader

0
 
        conn.bind(socket);
 
        Assert.assertEquals(0, conn.getMetrics().getRequestCount());
 
        final HttpRequest request = new BasicHttpRequest("GET", "/stuff", HttpVersion.HTTP_1_1);
        request.addHeader("User-Agent", "test");
 
        conn.sendRequestHeader(request);
        conn.flush();
 
        Assert.assertEquals(1, conn.getMetrics().getRequestCount());
        final String s = new String(outstream.toByteArray(), "ASCII");
        Assert.assertEquals("GET /stuff HTTP/1.1\r\nUser-Agent: test\r\n\r\n", s);
    } 
 
    @Test 
    public void testWriteResponseEntity() throws Exception { 
        final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        Mockito.when(socket.getOutputStream()).thenReturn(outstream);
Experience pair programming with AI  Get Codota for Java