Search in sources :

Example 21 with BasicHttpResponse

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

the class TestDefaultConnectionReuseStrategy method testConnectionTokens3.

@Test
public void testConnectionTokens3() throws Exception {
    // Use HTTP 1.1
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    response.addHeader("Transfer-Encoding", "chunked");
    response.addHeader("Connection", "yadda, keep-alive, close, dumdy");
    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)

Example 22 with BasicHttpResponse

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

the class TestDefaultConnectionReuseStrategy method testMultipleContentLength.

@Test
public void testMultipleContentLength() throws Exception {
    // Use HTTP 1.1
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    response.addHeader("Content-Length", "10");
    response.addHeader("Content-Length", "11");
    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)

Example 23 with BasicHttpResponse

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

the class TestDefaultConnectionReuseStrategy method testHTTP10Default.

@Test
public void testHTTP10Default() throws Exception {
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    response.setVersion(HttpVersion.HTTP_1_0);
    response.addHeader("Content-Length", "10");
    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)

Example 24 with BasicHttpResponse

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

the class TestDefaultConnectionReuseStrategy method testConnectionTokens1.

@Test
public void testConnectionTokens1() throws Exception {
    // Use HTTP 1.1
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    response.addHeader("Transfer-Encoding", "chunked");
    response.addHeader("Connection", "yadda, cLOSe, dumdy");
    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)

Example 25 with BasicHttpResponse

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

the class TestDefaultConnectionReuseStrategy method testConnectionTokens6.

@Test
public void testConnectionTokens6() throws Exception {
    // Use HTTP 1.1
    final HttpResponse response = new BasicHttpResponse(200, "OK");
    response.addHeader("Transfer-Encoding", "chunked");
    response.addHeader("Connection", "");
    response.addHeader("Proxy-Connection", "close");
    // Connection takes precedence over Proxy-Connection,
    // even if it is empty. Default for HTTP/1.1 is to 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)

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