Search in sources :

Example 11 with BasicHttpEntity

use of org.apache.hc.core5.http.io.entity.BasicHttpEntity 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)

Example 12 with BasicHttpEntity

use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.

the class TestStandardInterceptors method testRequestContentNullTypeAndEncoding.

@Test
public void testRequestContentNullTypeAndEncoding() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
    request.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, null, null));
    final HttpRequestInterceptor interceptor = RequestContent.INSTANCE;
    interceptor.process(request, request.getEntity(), context);
    Assertions.assertNull(request.getFirstHeader(HttpHeaders.CONTENT_TYPE));
    Assertions.assertNull(request.getFirstHeader(HttpHeaders.CONTENT_ENCODING));
}
Also used : BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) HttpRequestInterceptor(org.apache.hc.core5.http.HttpRequestInterceptor) BasicHttpEntity(org.apache.hc.core5.http.io.entity.BasicHttpEntity) Test(org.junit.jupiter.api.Test)

Example 13 with BasicHttpEntity

use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.

the class TestStandardInterceptors method testRequestContentEntityUnknownLengthHTTP11.

@Test
public void testRequestContentEntityUnknownLengthHTTP11() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
    request.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, -1, null));
    final HttpRequestInterceptor interceptor = RequestContent.INSTANCE;
    interceptor.process(request, request.getEntity(), context);
    final Header header = request.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
    Assertions.assertNotNull(header);
    Assertions.assertEquals("chunked", header.getValue());
    Assertions.assertNull(request.getFirstHeader(HttpHeaders.CONTENT_LENGTH));
}
Also used : BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) HttpRequestInterceptor(org.apache.hc.core5.http.HttpRequestInterceptor) BasicHttpEntity(org.apache.hc.core5.http.io.entity.BasicHttpEntity) Test(org.junit.jupiter.api.Test)

Example 14 with BasicHttpEntity

use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.

the class TestStandardInterceptors method testResponseContentEntityChunked.

@Test
public void testResponseContentEntityChunked() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
    response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, null, true));
    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);
}
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)

Example 15 with BasicHttpEntity

use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.

the class TestStandardInterceptors method testResponseConnControlEntityChunked.

@Test
public void testResponseConnControlEntityChunked() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
    response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, null, true));
    final ResponseConnControl interceptor = new ResponseConnControl();
    interceptor.process(response, response.getEntity(), context);
    final Header header = response.getFirstHeader(HttpHeaders.CONNECTION);
    Assertions.assertNull(header);
}
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

BasicHttpEntity (org.apache.hc.core5.http.io.entity.BasicHttpEntity)15 Test (org.junit.jupiter.api.Test)14 Header (org.apache.hc.core5.http.Header)11 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)11 BasicClassicHttpResponse (org.apache.hc.core5.http.message.BasicClassicHttpResponse)9 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)7 BasicClassicHttpRequest (org.apache.hc.core5.http.message.BasicClassicHttpRequest)6 HttpRequestInterceptor (org.apache.hc.core5.http.HttpRequestInterceptor)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ContentRetriever (eu.europeana.metis.network.AbstractHttpClient.ContentRetriever)1 StringContent (eu.europeana.metis.network.StringHttpClient.StringContent)1 Closeable (java.io.Closeable)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HttpPut (org.apache.hc.client5.http.classic.methods.HttpPut)1 CloseableHttpClient (org.apache.hc.client5.http.impl.classic.CloseableHttpClient)1 CloseableHttpResponse (org.apache.hc.client5.http.impl.classic.CloseableHttpResponse)1 HttpEntity (org.apache.hc.core5.http.HttpEntity)1