Search in sources :

Example 1 with FixedLengthStreamSourceConduit

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

the class HttpClientConnection method prepareResponseChannel.

private void prepareResponseChannel(ClientResponse response, ClientExchange exchange) {
    String encoding = response.getResponseHeaders().getLast(TRANSFER_ENCODING);
    boolean chunked = encoding != null && Headers.CHUNKED.equals(new HttpString(encoding));
    String length = response.getResponseHeaders().getFirst(CONTENT_LENGTH);
    if (exchange.getRequest().getMethod().equals(Methods.HEAD)) {
        connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener));
    } else if (chunked) {
        connection.getSourceChannel().setConduit(new ChunkedStreamSourceConduit(connection.getSourceChannel().getConduit(), pushBackStreamSourceConduit, bufferPool, responseFinishedListener, exchange));
    } else if (length != null) {
        try {
            long contentLength = Long.parseLong(length);
            connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), contentLength, responseFinishedListener));
        } catch (NumberFormatException e) {
            handleError(new IOException(e));
            throw e;
        }
    } else if (response.getProtocol().equals(Protocols.HTTP_1_1) && !Connectors.isEntityBodyAllowed(response.getResponseCode())) {
        connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener));
    } else {
        state |= CLOSE_REQ;
    }
}
Also used : HttpString(io.undertow.util.HttpString) IOException(java.io.IOException) FixedLengthStreamSourceConduit(io.undertow.conduits.FixedLengthStreamSourceConduit) ChunkedStreamSourceConduit(io.undertow.conduits.ChunkedStreamSourceConduit) HttpString(io.undertow.util.HttpString)

Aggregations

ChunkedStreamSourceConduit (io.undertow.conduits.ChunkedStreamSourceConduit)1 FixedLengthStreamSourceConduit (io.undertow.conduits.FixedLengthStreamSourceConduit)1 HttpString (io.undertow.util.HttpString)1 IOException (java.io.IOException)1