Search in sources :

Example 56 with BasicClassicHttpResponse

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

the class TestStandardInterceptors method testResponseConnControlUpgrade.

@Test
public void testResponseConnControlUpgrade() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final ResponseConnControl interceptor = new ResponseConnControl();
    final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
    response.addHeader(HttpHeaders.UPGRADE, "HTTP/2");
    interceptor.process(response, response.getEntity(), context);
    final Header header = response.getFirstHeader(HttpHeaders.CONNECTION);
    Assertions.assertNotNull(header);
    Assertions.assertEquals("upgrade", header.getValue());
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 57 with BasicClassicHttpResponse

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

the class TestStandardInterceptors method testResponseServerMissing.

@Test
public void testResponseServerMissing() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
    final ResponseServer interceptor = new ResponseServer();
    interceptor.process(response, response.getEntity(), context);
    final Header h1 = response.getFirstHeader(HttpHeaders.SERVER);
    Assertions.assertNull(h1);
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 58 with BasicClassicHttpResponse

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

the class TestStandardInterceptors method testResponseContentOverwriteHeaders.

@Test
public void testResponseContentOverwriteHeaders() throws Exception {
    final ResponseContent interceptor = new ResponseContent(true);
    final HttpContext context = new BasicHttpContext(null);
    final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
    response.addHeader(new BasicHeader(HttpHeaders.CONTENT_LENGTH, "10"));
    response.addHeader(new BasicHeader(HttpHeaders.TRANSFER_ENCODING, "whatever"));
    interceptor.process(response, response.getEntity(), context);
    Assertions.assertEquals("0", response.getFirstHeader(HttpHeaders.CONTENT_LENGTH).getValue());
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 59 with BasicClassicHttpResponse

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

the class TestStandardInterceptors method testResponseConnControlStatusCode.

@Test
public void testResponseConnControlStatusCode() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
    request.addHeader(new BasicHeader(HttpHeaders.CONNECTION, "keep-alive"));
    context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
    final ResponseConnControl interceptor = new ResponseConnControl();
    final int[] statusCodes = new int[] { HttpStatus.SC_BAD_REQUEST, HttpStatus.SC_REQUEST_TIMEOUT, HttpStatus.SC_LENGTH_REQUIRED, HttpStatus.SC_REQUEST_TOO_LONG, HttpStatus.SC_REQUEST_URI_TOO_LONG, HttpStatus.SC_SERVICE_UNAVAILABLE, HttpStatus.SC_NOT_IMPLEMENTED };
    for (final int statusCode : statusCodes) {
        final ClassicHttpResponse response = new BasicClassicHttpResponse(statusCode, "Unreasonable");
        interceptor.process(response, response.getEntity(), context);
        final Header header = response.getFirstHeader(HttpHeaders.CONNECTION);
        Assertions.assertNotNull(header);
        Assertions.assertEquals("close", header.getValue());
    }
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 60 with BasicClassicHttpResponse

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

the class TestStandardInterceptors method testResponseContentEntityContentLenghtDelimited.

@Test
public void testResponseContentEntityContentLenghtDelimited() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
    response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, 10, null));
    final ResponseContent interceptor = new ResponseContent();
    interceptor.process(response, response.getEntity(), context);
    final Header h1 = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
    Assertions.assertNotNull(h1);
    Assertions.assertEquals("10", h1.getValue());
    final Header h2 = response.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
    Assertions.assertNull(h2);
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) BasicHttpEntity(org.apache.hc.core5.http.io.entity.BasicHttpEntity) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

BasicClassicHttpResponse (org.apache.hc.core5.http.message.BasicClassicHttpResponse)69 Test (org.junit.jupiter.api.Test)57 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)56 Header (org.apache.hc.core5.http.Header)34 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)29 BasicClassicHttpRequest (org.apache.hc.core5.http.message.BasicClassicHttpRequest)19 ClassicHttpRequest (org.apache.hc.core5.http.ClassicHttpRequest)14 StringEntity (org.apache.hc.core5.http.io.entity.StringEntity)13 HttpEntity (org.apache.hc.core5.http.HttpEntity)12 HttpCoreContext (org.apache.hc.core5.http.protocol.HttpCoreContext)11 HttpClientConnection (org.apache.hc.core5.http.io.HttpClientConnection)10 HttpProcessor (org.apache.hc.core5.http.protocol.HttpProcessor)10 BasicHttpEntity (org.apache.hc.core5.http.io.entity.BasicHttpEntity)9 TimeValue (org.apache.hc.core5.util.TimeValue)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)6 HttpResponse (org.apache.hc.core5.http.HttpResponse)4 Timeout (org.apache.hc.core5.util.Timeout)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3