Search in sources :

Example 26 with BasicHttpResponse

use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.

the class TestDefaultConnectionReuseStrategy method testRequestExplicitClose.

@Test
public void testRequestExplicitClose() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, "/");
    request.addHeader("Connection", "close");
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    response.addHeader("Transfer-Encoding", "chunked");
    response.addHeader("Connection", "keep-alive");
    Assertions.assertFalse(reuseStrategy.keepAlive(request, response, context));
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpResponse(org.apache.hc.core5.http.HttpResponse) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 27 with BasicHttpResponse

use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.

the class TestDefaultConnectionReuseStrategy method testHttp204ContentLengthEqualToZero.

@Test
public void testHttp204ContentLengthEqualToZero() throws Exception {
    final HttpResponse response = new BasicHttpResponse(204, "OK");
    response.addHeader("Content-Length", "0");
    response.addHeader("Connection", "keep-alive");
    Assertions.assertTrue(reuseStrategy.keepAlive(null, response, context));
}
Also used : BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpResponse(org.apache.hc.core5.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 28 with BasicHttpResponse

use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.

the class TestDefaultConnectionReuseStrategy method testHTTP11Default.

@Test
public void testHTTP11Default() throws Exception {
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    response.addHeader("Content-Length", "10");
    Assertions.assertTrue(reuseStrategy.keepAlive(null, response, context));
}
Also used : BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpResponse(org.apache.hc.core5.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 29 with BasicHttpResponse

use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.

the class TestDefaultConnectionReuseStrategy method testRequestNoExplicitClose.

@Test
public void testRequestNoExplicitClose() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, "/");
    request.addHeader("Connection", "blah, blah, blah");
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    response.addHeader("Transfer-Encoding", "chunked");
    response.addHeader("Connection", "keep-alive");
    Assertions.assertTrue(reuseStrategy.keepAlive(request, response, context));
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpResponse(org.apache.hc.core5.http.HttpResponse) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 30 with BasicHttpResponse

use of org.apache.hc.core5.http.message.BasicHttpResponse in project httpcomponents-core by apache.

the class TestDefaultConnectionReuseStrategy method testNoContentLengthResponseHttp1_1.

@Test
public void testNoContentLengthResponseHttp1_1() throws Exception {
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    Assertions.assertFalse(reuseStrategy.keepAlive(null, response, context));
}
Also used : BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpResponse(org.apache.hc.core5.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

BasicHttpResponse (org.apache.hc.core5.http.message.BasicHttpResponse)60 HttpResponse (org.apache.hc.core5.http.HttpResponse)57 Test (org.junit.jupiter.api.Test)40 HttpRequest (org.apache.hc.core5.http.HttpRequest)15 Header (org.apache.hc.core5.http.Header)14 HttpException (org.apache.hc.core5.http.HttpException)11 IOException (java.io.IOException)10 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)9 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)9 InetSocketAddress (java.net.InetSocketAddress)8 EntityDetails (org.apache.hc.core5.http.EntityDetails)8 ByteBuffer (java.nio.ByteBuffer)7 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)7 Test (org.junit.Test)7 ProtocolException (org.apache.hc.core5.http.ProtocolException)6 AsyncEntityProducer (org.apache.hc.core5.http.nio.AsyncEntityProducer)6 AsyncServerExchangeHandler (org.apache.hc.core5.http.nio.AsyncServerExchangeHandler)6 Message (org.apache.hc.core5.http.Message)5 CapacityChannel (org.apache.hc.core5.http.nio.CapacityChannel)5 DataStreamChannel (org.apache.hc.core5.http.nio.DataStreamChannel)5