Search in sources :

Example 1 with PreChunkedStreamSinkConduit

use of io.undertow.conduits.PreChunkedStreamSinkConduit in project undertow by undertow-io.

the class HttpTransferEncoding method handleExplicitTransferEncoding.

private static StreamSinkConduit handleExplicitTransferEncoding(HttpServerExchange exchange, StreamSinkConduit channel, ConduitListener<StreamSinkConduit> finishListener, HeaderMap responseHeaders, String transferEncodingHeader, boolean headRequest) {
    HttpString transferEncoding = new HttpString(transferEncodingHeader);
    if (transferEncoding.equals(Headers.CHUNKED)) {
        if (headRequest) {
            return channel;
        }
        Boolean preChunked = exchange.getAttachment(HttpAttachments.PRE_CHUNKED_RESPONSE);
        if (preChunked != null && preChunked) {
            return new PreChunkedStreamSinkConduit(channel, finishListener, exchange);
        } else {
            return new ChunkedStreamSinkConduit(channel, exchange.getConnection().getByteBufferPool(), true, !exchange.isPersistent(), responseHeaders, finishListener, exchange);
        }
    } else {
        if (headRequest) {
            return channel;
        }
        log.trace("Cancelling persistence because response is identity with no content length");
        // make it not persistent - very unfortunate for the next request handler really...
        exchange.setPersistent(false);
        responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
        return new FinishableStreamSinkConduit(channel, terminateResponseListener(exchange));
    }
}
Also used : PreChunkedStreamSinkConduit(io.undertow.conduits.PreChunkedStreamSinkConduit) ChunkedStreamSinkConduit(io.undertow.conduits.ChunkedStreamSinkConduit) PreChunkedStreamSinkConduit(io.undertow.conduits.PreChunkedStreamSinkConduit) FinishableStreamSinkConduit(io.undertow.conduits.FinishableStreamSinkConduit) HttpString(io.undertow.util.HttpString)

Aggregations

ChunkedStreamSinkConduit (io.undertow.conduits.ChunkedStreamSinkConduit)1 FinishableStreamSinkConduit (io.undertow.conduits.FinishableStreamSinkConduit)1 PreChunkedStreamSinkConduit (io.undertow.conduits.PreChunkedStreamSinkConduit)1 HttpString (io.undertow.util.HttpString)1