Search in sources :

Example 1 with StreamSinkChannelWrappingConduit

use of org.xnio.conduits.StreamSinkChannelWrappingConduit in project undertow by undertow-io.

the class Http2ServerConnection method sendOutOfBandResponse.

@Override
public HttpServerExchange sendOutOfBandResponse(HttpServerExchange exchange) {
    if (exchange == null || !HttpContinue.requiresContinueResponse(exchange)) {
        throw UndertowMessages.MESSAGES.outOfBandResponseOnlyAllowedFor100Continue();
    }
    final HttpServerExchange newExchange = new HttpServerExchange(this);
    for (HttpString header : exchange.getRequestHeaders().getHeaderNames()) {
        newExchange.getRequestHeaders().putAll(header, exchange.getRequestHeaders().get(header));
    }
    newExchange.setProtocol(exchange.getProtocol());
    newExchange.setRequestMethod(exchange.getRequestMethod());
    exchange.setRequestURI(exchange.getRequestURI(), exchange.isHostIncludedInRequestURI());
    exchange.setRequestPath(exchange.getRequestPath());
    exchange.setRelativePath(exchange.getRelativePath());
    newExchange.setPersistent(true);
    Connectors.terminateRequest(newExchange);
    newExchange.addResponseWrapper(new ConduitWrapper<StreamSinkConduit>() {

        @Override
        public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) {
            HeaderMap headers = newExchange.getResponseHeaders();
            DateUtils.addDateHeaderIfRequired(exchange);
            headers.add(STATUS, exchange.getStatusCode());
            Connectors.flattenCookies(exchange);
            Http2HeadersStreamSinkChannel sink = new Http2HeadersStreamSinkChannel(channel, requestChannel.getStreamId(), headers);
            StreamSinkChannelWrappingConduit ret = new StreamSinkChannelWrappingConduit(sink);
            ret.setWriteReadyHandler(new WriteReadyHandler.ChannelListenerHandler(Connectors.getConduitSinkChannel(exchange)));
            return ret;
        }
    });
    continueSent = true;
    return newExchange;
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) Http2HeadersStreamSinkChannel(io.undertow.protocols.http2.Http2HeadersStreamSinkChannel) HeaderMap(io.undertow.util.HeaderMap) StreamSinkConduit(org.xnio.conduits.StreamSinkConduit) StreamSinkChannelWrappingConduit(org.xnio.conduits.StreamSinkChannelWrappingConduit) HttpString(io.undertow.util.HttpString)

Aggregations

Http2HeadersStreamSinkChannel (io.undertow.protocols.http2.Http2HeadersStreamSinkChannel)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1 StreamSinkChannelWrappingConduit (org.xnio.conduits.StreamSinkChannelWrappingConduit)1 StreamSinkConduit (org.xnio.conduits.StreamSinkConduit)1