// add least for websocket upgrades we can have a content length
final long contentLength;
try {
contentLength = Long.parseLong(contentLengthHeader);
// fixed-length response
wrappedConduit = new FixedLengthStreamSinkConduit(channel, contentLength, true, !stillPersistent, finishListener);
} catch (NumberFormatException e) {
// assume that the response is unbounded, but forbid persistence (this will cause subsequent requests to fail when they write their replies)
stillPersistent = false;
wrappedConduit = new FinishableStreamSinkConduit(channel, terminateResponseListener(exchange));
}
} else {
wrappedConduit = new FixedLengthStreamSinkConduit(channel, 0L, true, !stillPersistent, finishListener);
}
} else if (!transferEncoding.equals(Headers.IDENTITY)) {
final ConduitListener<StreamSinkConduit> finishListener = stillPersistent ? terminateResponseListener(exchange) : null;
wrappedConduit = new ChunkedStreamSinkConduit(channel, true, !stillPersistent, finishListener, exchange);
} else if (contentLengthHeader != null) {
final long contentLength;
try {
contentLength = Long.parseLong(contentLengthHeader);
final ConduitListener<StreamSinkConduit> finishListener = stillPersistent ? terminateResponseListener(exchange) : null;
// fixed-length response
wrappedConduit = new FixedLengthStreamSinkConduit(channel, contentLength, true, !stillPersistent, finishListener);
} catch (NumberFormatException e) {
// assume that the response is unbounded, but forbid persistence (this will cause subsequent requests to fail when they write their replies)
stillPersistent = false;
wrappedConduit = new FinishableStreamSinkConduit(channel, terminateResponseListener(exchange));
}