Respect existing content-length for HTTP HEAD
Closes gh-23484
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
/**
|
||||
* {@link ServerHttpResponse} decorator for HTTP HEAD requests.
|
||||
@@ -52,7 +53,11 @@ public class HttpHeadResponseDecorator extends ServerHttpResponseDecorator {
|
||||
DataBufferUtils.release(buffer);
|
||||
return next;
|
||||
})
|
||||
.doOnNext(count -> getHeaders().setContentLength(count))
|
||||
.doOnNext(length -> {
|
||||
if (length > 0 || getHeaders().getFirst(HttpHeaders.CONTENT_LENGTH) == null) {
|
||||
getHeaders().setContentLength(length);
|
||||
}
|
||||
})
|
||||
.then();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user