use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseContentEntityWithTrailers.
@Test
public void testResponseContentEntityWithTrailers() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(HttpEntities.create("whatever", StandardCharsets.US_ASCII, new BasicHeader("h1", "this"), new BasicHeader("h1", "that"), new BasicHeader("h2", "this and that")));
final ResponseContent interceptor = new ResponseContent();
interceptor.process(response, response.getEntity(), context);
final Header header1 = response.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
Assertions.assertNotNull(header1);
final Header header2 = response.getFirstHeader(HttpHeaders.TRAILER);
Assertions.assertNotNull(header2);
Assertions.assertEquals("h1, h2", header2.getValue());
}
use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseContentAddHeaders.
@Test
public void testResponseContentAddHeaders() throws Exception {
final ResponseContent interceptor = new ResponseContent(true);
final HttpContext context = new BasicHttpContext(null);
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
interceptor.process(response, response.getEntity(), context);
Assertions.assertEquals("0", response.getFirstHeader(HttpHeaders.CONTENT_LENGTH).getValue());
Assertions.assertNull(response.getFirstHeader(HttpHeaders.TRANSFER_ENCODING));
}
use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseConnControlClientRequest.
@Test
public void testResponseConnControlClientRequest() 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 ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(new StringEntity("whatever"));
final ResponseConnControl interceptor = new ResponseConnControl();
interceptor.process(response, response.getEntity(), context);
final Header header = response.getFirstHeader(HttpHeaders.CONNECTION);
Assertions.assertNotNull(header);
Assertions.assertEquals("keep-alive", header.getValue());
}
use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseConnControlClientRequestMixUp.
@Test
public void testResponseConnControlClientRequestMixUp() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
request.addHeader(new BasicHeader(HttpHeaders.CONNECTION, "blah, keep-alive, close"));
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
final ResponseConnControl interceptor = new ResponseConnControl();
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
interceptor.process(response, response.getEntity(), context);
final Header header = response.getFirstHeader(HttpHeaders.CONNECTION);
Assertions.assertNotNull(header);
Assertions.assertEquals("close", header.getValue());
}
use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseConnControlClientRequest2.
@Test
public void testResponseConnControlClientRequest2() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(new StringEntity("whatever"));
final ResponseConnControl interceptor = new ResponseConnControl();
interceptor.process(response, response.getEntity(), context);
final Header header = response.getFirstHeader(HttpHeaders.CONNECTION);
Assertions.assertNull(header);
}
Aggregations