Search in sources :

Example 16 with BasicHttpResponse

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

the class BasicResponseBuilder method build.

@Override
public BasicHttpResponse build() {
    final BasicHttpResponse result = new BasicHttpResponse(getStatus());
    result.setVersion(getVersion());
    result.setHeaders(getHeaders());
    return result;
}
Also used : BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse)

Example 17 with BasicHttpResponse

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

the class AsyncPushBuilder method build.

@Override
public AsyncPushProducer build() {
    final HttpResponse response = new BasicHttpResponse(getStatus());
    response.setVersion(getVersion());
    response.setHeaders(getHeaders());
    return new BasicPushProducer(response, entityProducer);
}
Also used : BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpResponse(org.apache.hc.core5.http.HttpResponse)

Example 18 with BasicHttpResponse

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

the class AsyncResponseBuilder method build.

@Override
public AsyncResponseProducer build() {
    final BasicHttpResponse response = new BasicHttpResponse(getStatus());
    response.setVersion(getVersion());
    response.setHeaders(getHeaders());
    return new BasicResponseProducer(response, entityProducer);
}
Also used : BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse)

Example 19 with BasicHttpResponse

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

the class AsyncServerExpectationFilter method handle.

@Override
public final AsyncDataConsumer handle(final HttpRequest request, final EntityDetails entityDetails, final HttpContext context, final AsyncFilterChain.ResponseTrigger responseTrigger, final AsyncFilterChain chain) throws HttpException, IOException {
    if (entityDetails != null) {
        final Header h = request.getFirstHeader(HttpHeaders.EXPECT);
        if (h != null && HeaderElements.CONTINUE.equalsIgnoreCase(h.getValue())) {
            final boolean verified = verify(request, context);
            if (verified) {
                responseTrigger.sendInformation(new BasicHttpResponse(HttpStatus.SC_CONTINUE));
            } else {
                final HttpResponse expectationFailed = new BasicHttpResponse(HttpStatus.SC_EXPECTATION_FAILED);
                final AsyncEntityProducer responseContentProducer = generateResponseContent(expectationFailed);
                responseTrigger.submitResponse(expectationFailed, responseContentProducer);
                return null;
            }
        }
    }
    return chain.proceed(request, entityDetails, context, responseTrigger);
}
Also used : BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) Header(org.apache.hc.core5.http.Header) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpResponse(org.apache.hc.core5.http.HttpResponse)

Example 20 with BasicHttpResponse

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

the class BasicAsyncServerExpectationDecorator method handleRequest.

@Override
public final void handleRequest(final HttpRequest request, final EntityDetails entityDetails, final ResponseChannel responseChannel, final HttpContext context) throws HttpException, IOException {
    if (entityDetails != null) {
        final Header h = request.getFirstHeader(HttpHeaders.EXPECT);
        if (h != null && HeaderElements.CONTINUE.equalsIgnoreCase(h.getValue())) {
            final AsyncResponseProducer producer = verify(request, context);
            if (producer != null) {
                responseProducerRef.set(producer);
                producer.sendResponse(responseChannel, context);
                return;
            }
            responseChannel.sendInformation(new BasicHttpResponse(HttpStatus.SC_CONTINUE), context);
        }
    }
    handler.handleRequest(request, entityDetails, responseChannel, context);
}
Also used : AsyncResponseProducer(org.apache.hc.core5.http.nio.AsyncResponseProducer) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) Header(org.apache.hc.core5.http.Header)

Aggregations

BasicHttpResponse (org.apache.hc.core5.http.message.BasicHttpResponse)60 HttpResponse (org.apache.hc.core5.http.HttpResponse)57 Test (org.junit.jupiter.api.Test)40 HttpRequest (org.apache.hc.core5.http.HttpRequest)15 Header (org.apache.hc.core5.http.Header)14 HttpException (org.apache.hc.core5.http.HttpException)11 IOException (java.io.IOException)10 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)9 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)9 InetSocketAddress (java.net.InetSocketAddress)8 EntityDetails (org.apache.hc.core5.http.EntityDetails)8 ByteBuffer (java.nio.ByteBuffer)7 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)7 Test (org.junit.Test)7 ProtocolException (org.apache.hc.core5.http.ProtocolException)6 AsyncEntityProducer (org.apache.hc.core5.http.nio.AsyncEntityProducer)6 AsyncServerExchangeHandler (org.apache.hc.core5.http.nio.AsyncServerExchangeHandler)6 Message (org.apache.hc.core5.http.Message)5 CapacityChannel (org.apache.hc.core5.http.nio.CapacityChannel)5 DataStreamChannel (org.apache.hc.core5.http.nio.DataStreamChannel)5