use of org.apache.hc.core5.http.protocol.RequestExpectContinue 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.protocol.RequestExpectContinue in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestExpectContinueIgnoreNonenclosingRequests.
@Test
public void testRequestExpectContinueIgnoreNonenclosingRequests() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
final RequestExpectContinue interceptor = new RequestExpectContinue();
interceptor.process(request, request.getEntity(), context);
Assertions.assertEquals(0, request.getHeaders().length);
}
use of org.apache.hc.core5.http.protocol.RequestExpectContinue in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestExpectContinueHTTP10.
@Test
public void testRequestExpectContinueHTTP10() throws Exception {
final HttpCoreContext context = HttpCoreContext.create();
context.setProtocolVersion(HttpVersion.HTTP_1_0);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.setEntity(new StringEntity("whatever", StandardCharsets.US_ASCII));
final RequestExpectContinue interceptor = new RequestExpectContinue();
interceptor.process(request, request.getEntity(), context);
final Header header = request.getFirstHeader(HttpHeaders.EXPECT);
Assertions.assertNull(header);
}
use of org.apache.hc.core5.http.protocol.RequestExpectContinue in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestExpectContinueZeroContent.
@Test
public void testRequestExpectContinueZeroContent() throws Exception {
final HttpCoreContext context = HttpCoreContext.create();
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.setEntity(new StringEntity("", StandardCharsets.US_ASCII));
final RequestExpectContinue interceptor = new RequestExpectContinue();
interceptor.process(request, request.getEntity(), context);
final Header header = request.getFirstHeader(HttpHeaders.EXPECT);
Assertions.assertNull(header);
}
use of org.apache.hc.core5.http.protocol.RequestExpectContinue in project californium by eclipse.
the class HttpClientFactory method createClient.
/**
* Create the pooled asynchronous http client.
*
* @param config configuration for the http client
* @return asynchronous http client
* @since 3.0 (changed parameter to Configuration)
*/
public static CloseableHttpAsyncClient createClient(Configuration config) {
int connectionIdleSecs = config.getTimeAsInt(Proxy2Config.HTTP_CONNECTION_IDLE_TIMEOUT, TimeUnit.SECONDS);
final CloseableHttpAsyncClient client = HttpAsyncClientBuilder.create().disableCookieManagement().setDefaultRequestConfig(createCustomRequestConfig(config)).setConnectionManager(createPoolingConnManager(config)).setVersionPolicy(HttpVersionPolicy.NEGOTIATE).setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(Timeout.ofSeconds(connectionIdleSecs)).build()).addRequestInterceptorFirst(new RequestConnControl()).addRequestInterceptorFirst(new RequestDate()).addRequestInterceptorFirst(new RequestExpectContinue()).addRequestInterceptorFirst(new RequestTargetHost()).addRequestInterceptorFirst(new RequestUserAgent()).setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy() {
@Override
public TimeValue getKeepAliveDuration(HttpResponse response, HttpContext context) {
TimeValue keepAlive = super.getKeepAliveDuration(response, context);
if (keepAlive == null || keepAlive.getDuration() < 0) {
// Keep connections alive if a keep-alive value
// has not be explicitly set by the server
keepAlive = KEEP_ALIVE;
}
return keepAlive;
}
}).build();
client.start();
return client;
}
Aggregations