Search in sources :

Example 26 with ProtocolVersion

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

the class H2RequestContent method process.

@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context) throws HttpException, IOException {
    Args.notNull(context, "HTTP context");
    final ProtocolVersion ver = context.getProtocolVersion();
    if (ver.getMajor() < 2) {
        super.process(request, entity, context);
    } else if (entity != null) {
        final String method = request.getMethod();
        if (Method.TRACE.isSame(method)) {
            throw new ProtocolException("TRACE request may not enclose an entity");
        }
        MessageSupport.addContentTypeHeader(request, entity);
        MessageSupport.addContentEncodingHeader(request, entity);
        MessageSupport.addTrailerHeader(request, entity);
    }
}
Also used : ProtocolException(org.apache.hc.core5.http.ProtocolException) ProtocolVersion(org.apache.hc.core5.http.ProtocolVersion)

Example 27 with ProtocolVersion

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

the class H2RequestTargetHost method process.

@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context) throws HttpException, IOException {
    Args.notNull(context, "HTTP context");
    final ProtocolVersion ver = context.getProtocolVersion();
    if (ver.getMajor() < 2) {
        super.process(request, entity, context);
    }
}
Also used : ProtocolVersion(org.apache.hc.core5.http.ProtocolVersion)

Example 28 with ProtocolVersion

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

the class H2RequestValidateHost method process.

@Override
public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context) throws HttpException, IOException {
    Args.notNull(context, "HTTP context");
    final ProtocolVersion ver = context.getProtocolVersion();
    if (ver.getMajor() < 2) {
        super.process(request, entity, context);
    }
}
Also used : ProtocolVersion(org.apache.hc.core5.http.ProtocolVersion)

Example 29 with ProtocolVersion

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

the class H2ResponseContent method process.

@Override
public void process(final HttpResponse response, final EntityDetails entity, final HttpContext context) throws HttpException, IOException {
    Args.notNull(context, "HTTP context");
    final ProtocolVersion ver = context.getProtocolVersion();
    if (ver.getMajor() < 2) {
        super.process(response, entity, context);
    } else if (entity != null) {
        MessageSupport.addContentTypeHeader(response, entity);
        MessageSupport.addContentEncodingHeader(response, entity);
        MessageSupport.addTrailerHeader(response, entity);
    }
}
Also used : ProtocolVersion(org.apache.hc.core5.http.ProtocolVersion)

Example 30 with ProtocolVersion

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

the class ServerHttp1StreamHandler method consumeHeader.

void consumeHeader(final HttpRequest request, final EntityDetails requestEntityDetails) throws HttpException, IOException {
    if (done.get() || requestState != MessageState.HEADERS) {
        throw new ProtocolException("Unexpected message head");
    }
    receivedRequest = request;
    requestState = requestEntityDetails == null ? MessageState.COMPLETE : MessageState.BODY;
    AsyncServerExchangeHandler handler;
    try {
        handler = exchangeHandlerFactory.create(request, context);
    } catch (final MisdirectedRequestException ex) {
        handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_MISDIRECTED_REQUEST, ex.getMessage());
    } catch (final HttpException ex) {
        handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    }
    if (handler == null) {
        handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_NOT_FOUND, "Cannot handle request");
    }
    exchangeHandler = handler;
    final ProtocolVersion transportVersion = request.getVersion();
    if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
        throw new UnsupportedHttpVersionException(transportVersion);
    }
    context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
    context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
    try {
        httpProcessor.process(request, requestEntityDetails, context);
        exchangeHandler.handleRequest(request, requestEntityDetails, responseChannel, context);
    } catch (final HttpException ex) {
        if (!responseCommitted.get()) {
            final HttpResponse response = new BasicHttpResponse(ServerSupport.toStatusCode(ex));
            response.addHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE);
            final AsyncResponseProducer responseProducer = new BasicResponseProducer(response, ServerSupport.toErrorMessage(ex));
            exchangeHandler = new ImmediateResponseExchangeHandler(responseProducer);
            exchangeHandler.handleRequest(request, requestEntityDetails, responseChannel, context);
        } else {
            throw ex;
        }
    }
}
Also used : AsyncResponseProducer(org.apache.hc.core5.http.nio.AsyncResponseProducer) ProtocolException(org.apache.hc.core5.http.ProtocolException) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpResponse(org.apache.hc.core5.http.HttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpException(org.apache.hc.core5.http.HttpException) UnsupportedHttpVersionException(org.apache.hc.core5.http.UnsupportedHttpVersionException) ProtocolVersion(org.apache.hc.core5.http.ProtocolVersion) MisdirectedRequestException(org.apache.hc.core5.http.MisdirectedRequestException) ImmediateResponseExchangeHandler(org.apache.hc.core5.http.nio.support.ImmediateResponseExchangeHandler) BasicResponseProducer(org.apache.hc.core5.http.nio.support.BasicResponseProducer) AsyncServerExchangeHandler(org.apache.hc.core5.http.nio.AsyncServerExchangeHandler)

Aggregations

ProtocolVersion (org.apache.hc.core5.http.ProtocolVersion)35 ProtocolException (org.apache.hc.core5.http.ProtocolException)8 UnsupportedHttpVersionException (org.apache.hc.core5.http.UnsupportedHttpVersionException)8 Header (org.apache.hc.core5.http.Header)6 HttpException (org.apache.hc.core5.http.HttpException)6 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)4 ParseException (org.apache.hc.core5.http.ParseException)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ClassicHttpRequest (org.apache.hc.core5.http.ClassicHttpRequest)3 HttpHost (org.apache.hc.core5.http.HttpHost)3 HttpResponse (org.apache.hc.core5.http.HttpResponse)3 StringEntity (org.apache.hc.core5.http.io.entity.StringEntity)3 StatusLine (org.apache.hc.core5.http.message.StatusLine)3 Test (org.junit.jupiter.api.Test)3 URI (java.net.URI)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 SSLSession (javax.net.ssl.SSLSession)2