use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseContentEntityContentTypeAndEncoding.
@Test
public void testResponseContentEntityContentTypeAndEncoding() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, ContentType.parseLenient("whatever"), "whatever"));
final ResponseContent interceptor = new ResponseContent();
interceptor.process(response, response.getEntity(), context);
final Header h1 = response.getFirstHeader(HttpHeaders.CONTENT_TYPE);
Assertions.assertNotNull(h1);
Assertions.assertEquals("whatever", h1.getValue());
final Header h2 = response.getFirstHeader(HttpHeaders.CONTENT_ENCODING);
Assertions.assertNotNull(h2);
Assertions.assertEquals("whatever", h2.getValue());
}
use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestContentEntityUnknownLengthHTTP10.
@Test
public void testRequestContentEntityUnknownLengthHTTP10() throws Exception {
final HttpContext context = new BasicHttpContext(null);
context.setProtocolVersion(HttpVersion.HTTP_1_0);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, -1, null));
final HttpRequestInterceptor interceptor = RequestContent.INSTANCE;
Assertions.assertThrows(ProtocolException.class, () -> interceptor.process(request, request.getEntity(), context));
}
use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseContentEntityNoContentTypeAndEncoding.
@Test
public void testResponseContentEntityNoContentTypeAndEncoding() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, null));
final ResponseContent interceptor = new ResponseContent();
interceptor.process(response, response.getEntity(), context);
final Header h1 = response.getFirstHeader(HttpHeaders.CONTENT_TYPE);
Assertions.assertNull(h1);
final Header h2 = response.getFirstHeader(HttpHeaders.CONTENT_ENCODING);
Assertions.assertNull(h2);
}
use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseContentEntityUnknownContentLength.
@Test
public void testResponseContentEntityUnknownContentLength() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, null));
final ResponseContent interceptor = new ResponseContent();
interceptor.process(response, response.getEntity(), context);
final Header h1 = response.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
Assertions.assertNotNull(h1);
Assertions.assertEquals("chunked", h1.getValue());
final Header h2 = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
Assertions.assertNull(h2);
}
use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestContentTypeAndEncoding.
@Test
public void testRequestContentTypeAndEncoding() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, ContentType.parseLenient("whatever"), "whatever"));
final HttpRequestInterceptor interceptor = RequestContent.INSTANCE;
interceptor.process(request, request.getEntity(), context);
final Header h1 = request.getFirstHeader(HttpHeaders.CONTENT_TYPE);
Assertions.assertNotNull(h1);
Assertions.assertEquals("whatever", h1.getValue());
final Header h2 = request.getFirstHeader(HttpHeaders.CONTENT_ENCODING);
Assertions.assertNotNull(h2);
Assertions.assertEquals("whatever", h2.getValue());
}
Aggregations