Search in sources :

Example 11 with HttpCoreContext

use of org.apache.hc.core5.http.protocol.HttpCoreContext in project httpcomponents-core by apache.

the class ClientH2StreamMultiplexer method createRemotelyInitiatedStream.

@Override
H2StreamHandler createRemotelyInitiatedStream(final H2StreamChannel channel, final HttpProcessor httpProcessor, final BasicHttpConnectionMetrics connMetrics, final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) throws IOException {
    final HttpCoreContext context = HttpCoreContext.create();
    context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
    context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
    return new ClientPushH2StreamHandler(channel, httpProcessor, connMetrics, pushHandlerFactory != null ? pushHandlerFactory : this.pushHandlerFactory, context);
}
Also used : HttpCoreContext(org.apache.hc.core5.http.protocol.HttpCoreContext)

Example 12 with HttpCoreContext

use of org.apache.hc.core5.http.protocol.HttpCoreContext in project httpcomponents-core by apache.

the class ServerH2StreamMultiplexer method createRemotelyInitiatedStream.

@Override
H2StreamHandler createRemotelyInitiatedStream(final H2StreamChannel channel, final HttpProcessor httpProcessor, final BasicHttpConnectionMetrics connMetrics, final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) throws IOException {
    final HttpCoreContext context = HttpCoreContext.create();
    context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
    context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
    return new ServerH2StreamHandler(channel, httpProcessor, connMetrics, exchangeHandlerFactory, context);
}
Also used : HttpCoreContext(org.apache.hc.core5.http.protocol.HttpCoreContext)

Example 13 with HttpCoreContext

use of org.apache.hc.core5.http.protocol.HttpCoreContext in project httpcomponents-core by apache.

the class ClientHttp1StreamDuplexer method execute.

@Override
void execute(final RequestExecutionCommand executionCommand) throws HttpException, IOException {
    final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
    final HttpCoreContext context = HttpCoreContext.adapt(executionCommand.getContext());
    context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
    context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
    final ClientHttp1StreamHandler handler = new ClientHttp1StreamHandler(outputChannel, httpProcessor, http1Config, connectionReuseStrategy, exchangeHandler, context);
    pipeline.add(handler);
    outgoing = handler;
    if (handler.isOutputReady()) {
        handler.produceOutput();
    }
}
Also used : AsyncClientExchangeHandler(org.apache.hc.core5.http.nio.AsyncClientExchangeHandler) HttpCoreContext(org.apache.hc.core5.http.protocol.HttpCoreContext)

Example 14 with HttpCoreContext

use of org.apache.hc.core5.http.protocol.HttpCoreContext 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 15 with HttpCoreContext

use of org.apache.hc.core5.http.protocol.HttpCoreContext 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)

Aggregations

HttpCoreContext (org.apache.hc.core5.http.protocol.HttpCoreContext)56 BasicClassicHttpRequest (org.apache.hc.core5.http.message.BasicClassicHttpRequest)46 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)39 ClassicHttpRequest (org.apache.hc.core5.http.ClassicHttpRequest)33 BasicClassicHttpResponse (org.apache.hc.core5.http.message.BasicClassicHttpResponse)29 HttpHost (org.apache.hc.core5.http.HttpHost)26 Test (org.junit.jupiter.api.Test)25 Test (org.junit.Test)21 HttpEntity (org.apache.hc.core5.http.HttpEntity)16 StringEntity (org.apache.hc.core5.http.io.entity.StringEntity)13 HttpClientConnection (org.apache.hc.core5.http.io.HttpClientConnection)12 ByteArrayEntity (org.apache.hc.core5.http.io.entity.ByteArrayEntity)12 HttpProcessor (org.apache.hc.core5.http.protocol.HttpProcessor)12 AbstractHttpEntity (org.apache.hc.core5.http.io.entity.AbstractHttpEntity)9 Random (java.util.Random)8 Header (org.apache.hc.core5.http.Header)8 ArrayList (java.util.ArrayList)6 HttpRequest (org.apache.hc.core5.http.HttpRequest)6 ProtocolException (org.apache.hc.core5.http.ProtocolException)6 ContentType (org.apache.hc.core5.http.ContentType)5