Respect existing content-length for HTTP HEAD

Closes gh-23484
This commit is contained in:
Rossen Stoyanchev
2019-08-21 02:28:19 +03:00
parent 122e2ca2ac
commit b86c11cc9b
2 changed files with 80 additions and 2 deletions

View File

@@ -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();
}