Search in sources :

Example 6 with BasicHttpEntity

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());
}
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 7 with BasicHttpEntity

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));
}
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 8 with BasicHttpEntity

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);
}
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 9 with BasicHttpEntity

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);
}
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 10 with BasicHttpEntity

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());
}
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)

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