Code example for HttpRequest

Methods: containsHeadergetProtocolVersiongetRequestLine

0
 
        Assert.assertEquals(0, conn.getMetrics().getRequestCount());
 
        final HttpRequest request = conn.receiveRequestHeader();
        Assert.assertNotNull(request);
        Assert.assertEquals(HttpVersion.HTTP_1_1, request.getProtocolVersion());
        Assert.assertEquals("/", request.getRequestLine().getUri());
        Assert.assertEquals("GET", request.getRequestLine().getMethod());
        Assert.assertTrue(request.containsHeader("User-Agent"));
        Assert.assertEquals(1, conn.getMetrics().getRequestCount());
    } 
 
    @Test 
    public void testReadRequestEntity() throws Exception { 
        final String s = "POST / HTTP/1.1\r\nUser-Agent: test\r\nContent-Length: 3\r\n\r\n123";
        final ByteArrayInputStream instream = new ByteArrayInputStream(s.getBytes("ASCII"));
        Mockito.when(socket.getInputStream()).thenReturn(instream);
 
        conn.bind(socket);
 
Experience pair programming with AI  Get Codota for Java