Search in sources :

Example 1 with RequestExpectContinue

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));
}
Also used : HttpRequestInterceptor(org.apache.hc.core5.http.HttpRequestInterceptor) Test(org.junit.jupiter.api.Test)

Example 2 with RequestExpectContinue

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);
}
Also used : BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 3 with RequestExpectContinue

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);
}
Also used : StringEntity(org.apache.hc.core5.http.io.entity.StringEntity) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) Test(org.junit.jupiter.api.Test)

Example 4 with RequestExpectContinue

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);
}
Also used : StringEntity(org.apache.hc.core5.http.io.entity.StringEntity) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) Test(org.junit.jupiter.api.Test)

Example 5 with RequestExpectContinue

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;
}
Also used : RequestConnControl(org.apache.hc.core5.http.protocol.RequestConnControl) RequestDate(org.apache.hc.core5.http.protocol.RequestDate) RequestTargetHost(org.apache.hc.core5.http.protocol.RequestTargetHost) RequestExpectContinue(org.apache.hc.core5.http.protocol.RequestExpectContinue) DefaultConnectionKeepAliveStrategy(org.apache.hc.client5.http.impl.DefaultConnectionKeepAliveStrategy) RequestUserAgent(org.apache.hc.core5.http.protocol.RequestUserAgent) HttpContext(org.apache.hc.core5.http.protocol.HttpContext) CloseableHttpAsyncClient(org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient) HttpResponse(org.apache.hc.core5.http.HttpResponse) TimeValue(org.apache.hc.core5.util.TimeValue)

Aggregations

BasicClassicHttpRequest (org.apache.hc.core5.http.message.BasicClassicHttpRequest)6 Header (org.apache.hc.core5.http.Header)5 StringEntity (org.apache.hc.core5.http.io.entity.StringEntity)4 RequestExpectContinue (org.apache.hc.core5.http.protocol.RequestExpectContinue)4 Test (org.junit.jupiter.api.Test)4 RequestUserAgent (org.apache.hc.core5.http.protocol.RequestUserAgent)3 IOException (java.io.IOException)2 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)2 HttpEntity (org.apache.hc.core5.http.HttpEntity)2 HttpHost (org.apache.hc.core5.http.HttpHost)2 HttpResponse (org.apache.hc.core5.http.HttpResponse)2 AbstractHttpEntity (org.apache.hc.core5.http.io.entity.AbstractHttpEntity)2 ByteArrayEntity (org.apache.hc.core5.http.io.entity.ByteArrayEntity)2 BasicClassicHttpResponse (org.apache.hc.core5.http.message.BasicClassicHttpResponse)2 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)2 DefaultHttpProcessor (org.apache.hc.core5.http.protocol.DefaultHttpProcessor)2 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)2 HttpCoreContext (org.apache.hc.core5.http.protocol.HttpCoreContext)2 RequestConnControl (org.apache.hc.core5.http.protocol.RequestConnControl)2 RequestTargetHost (org.apache.hc.core5.http.protocol.RequestTargetHost)2