Code example for BasicHttpResponse

Methods: addHeader

0
 
        conn.bind(socket);
 
        Assert.assertEquals(0, conn.getMetrics().getResponseCount());
 
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.addHeader("User-Agent", "test");
 
        conn.sendResponseHeader(response);
        conn.flush();
 
        Assert.assertEquals(1, conn.getMetrics().getResponseCount());
        final String s = new String(outstream.toByteArray(), "ASCII");
        Assert.assertEquals("HTTP/1.1 200 OK\r\nUser-Agent: test\r\n\r\n", s);
    } 
 
    @Test 
    public void testWriteResponse100Head() throws Exception { 
        final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        Mockito.when(socket.getOutputStream()).thenReturn(outstream);