mirror of
https://github.com/jlengrand/helidon.git
synced 2026-03-10 08:21:17 +00:00
Methods contentLength and transferEncoding added (#2490)
Methods contentLength and transferEncoding added to response headers Signed-off-by: David Kral <david.k.kral@oracle.com>
This commit is contained in:
@@ -197,12 +197,13 @@ class NettyClientHandler extends SimpleChannelInboundHandler<HttpObject> {
|
||||
}
|
||||
|
||||
private boolean noContentLength(WebClientResponseHeaders headers) {
|
||||
return headers.first(Http.Header.CONTENT_LENGTH).isEmpty()
|
||||
|| headers.first(Http.Header.CONTENT_LENGTH).get().equals("0");
|
||||
return headers.contentLength()
|
||||
.map(value -> value == 0)
|
||||
.orElse(true);
|
||||
}
|
||||
|
||||
private boolean notChunked(WebClientResponseHeaders headers) {
|
||||
return headers.first(Http.Header.TRANSFER_ENCODING).isEmpty();
|
||||
return !headers.transferEncoding().contains("chunked");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -79,4 +79,19 @@ public interface WebClientResponseHeaders extends Headers {
|
||||
*/
|
||||
Optional<String> etag();
|
||||
|
||||
/**
|
||||
* Content length of the response payload.
|
||||
*
|
||||
* @return content length
|
||||
*/
|
||||
Optional<Long> contentLength();
|
||||
|
||||
/**
|
||||
* Transfer encoding of the response.
|
||||
*
|
||||
* @return transfer encoding
|
||||
*/
|
||||
List<String> transferEncoding();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -95,6 +95,18 @@ class WebClientResponseHeadersImpl extends ReadOnlyParameters implements WebClie
|
||||
return first(Http.Header.ETAG).map(this::unquoteETag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Long> contentLength() {
|
||||
return first(Http.Header.CONTENT_LENGTH)
|
||||
.map(Long::parseLong)
|
||||
.or(Optional::empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> transferEncoding() {
|
||||
return all(Http.Header.TRANSFER_ENCODING);
|
||||
}
|
||||
|
||||
private String unquoteETag(String etag) {
|
||||
if (etag == null || etag.isEmpty()) {
|
||||
return etag;
|
||||
|
||||
Reference in New Issue
Block a user