use of org.apache.hc.core5.http.HttpRequestInterceptor in project httpcomponents-core by apache.
the class TestChainBuilder method testBuildChain.
@Test
public void testBuildChain() throws Exception {
final ChainBuilder<HttpRequestInterceptor> cb = new ChainBuilder<>();
final HttpRequestInterceptor i1 = RequestContent.INSTANCE;
final HttpRequestInterceptor i2 = RequestTargetHost.INSTANCE;
final HttpRequestInterceptor i3 = RequestConnControl.INSTANCE;
final HttpRequestInterceptor i4 = RequestUserAgent.INSTANCE;
final HttpRequestInterceptor i5 = new RequestExpectContinue();
cb.addFirst(i1);
cb.addAllFirst(i2, i3);
cb.addFirst(null);
cb.addAllFirst((List<HttpRequestInterceptor>) null);
cb.addLast(i4);
cb.addLast(null);
cb.addAllLast(i5);
cb.addAllLast((List<HttpRequestInterceptor>) null);
cb.addFirst(i1);
cb.addAllLast(i3, i4, i5);
final LinkedList<HttpRequestInterceptor> list = cb.build();
Assertions.assertNotNull(list);
Assertions.assertEquals(5, list.size());
Assertions.assertSame(i1, list.get(0));
Assertions.assertSame(i2, list.get(1));
Assertions.assertSame(i3, list.get(2));
Assertions.assertSame(i4, list.get(3));
Assertions.assertSame(i5, list.get(4));
}
use of org.apache.hc.core5.http.HttpRequestInterceptor in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestContentNullEntity.
@Test
public void testRequestContentNullEntity() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
final HttpRequestInterceptor interceptor = RequestContent.INSTANCE;
interceptor.process(request, request.getEntity(), context);
final Header header = request.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
Assertions.assertNull(header);
Assertions.assertNull(request.getFirstHeader(HttpHeaders.TRANSFER_ENCODING));
}
use of org.apache.hc.core5.http.HttpRequestInterceptor in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestConnControlCustom.
@Test
public void testRequestConnControlCustom() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
final Header myheader = new BasicHeader(HttpHeaders.CONNECTION, "close");
request.addHeader(myheader);
final HttpRequestInterceptor interceptor = RequestConnControl.INSTANCE;
interceptor.process(request, request.getEntity(), context);
final Header header = request.getFirstHeader(HttpHeaders.CONNECTION);
Assertions.assertNotNull(header);
Assertions.assertEquals("close", header.getValue());
Assertions.assertSame(header, myheader);
}
use of org.apache.hc.core5.http.HttpRequestInterceptor in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestDateInvalidInput.
@Test
public void testRequestDateInvalidInput() throws Exception {
final HttpRequestInterceptor interceptor = RequestDate.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () -> interceptor.process(null, null, null));
}
use of org.apache.hc.core5.http.HttpRequestInterceptor in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestContentProtocolException.
@Test
public void testRequestContentProtocolException() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/");
request1.addHeader(new BasicHeader(HttpHeaders.TRANSFER_ENCODING, "chunked"));
final BasicClassicHttpRequest request2 = new BasicClassicHttpRequest(Method.POST, "/");
request2.addHeader(new BasicHeader(HttpHeaders.CONTENT_LENGTH, "12"));
final HttpRequestInterceptor interceptor = RequestContent.INSTANCE;
Assertions.assertThrows(ProtocolException.class, () -> interceptor.process(request1, request1.getEntity(), context));
Assertions.assertThrows(ProtocolException.class, () -> interceptor.process(request2, request2.getEntity(), context));
}
Aggregations