can not Override http header
@@ -83,14 +83,12 @@ public class FileSizeFilter implements WebFilter {
BodyInserter bodyInserter = BodyInserters.fromPublisher(Mono.just(size), DataBuffer.class);
HttpHeaders headers = new HttpHeaders();
headers.putAll(exchange.getRequest().getHeaders());
- // the new content type will be computed by bodyInserter
- // and then set in the request decorator
headers.remove(HttpHeaders.CONTENT_LENGTH);
CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage(
exchange, headers);
return bodyInserter.insert(outputMessage, new BodyInserterContext())
.then(Mono.defer(() -> {
- ServerHttpRequest decorator = decorate(exchange, headers, outputMessage);
+ ServerHttpRequest decorator = decorate(exchange, outputMessage);
return chain.filter(exchange.mutate().request(decorator).build());
}));
@@ -100,22 +98,8 @@ public class FileSizeFilter implements WebFilter {
}
- ServerHttpRequestDecorator decorate(final ServerWebExchange exchange, final HttpHeaders headers, final CachedBodyOutputMessage outputMessage) {
-
+ private ServerHttpRequestDecorator decorate(final ServerWebExchange exchange, final CachedBodyOutputMessage outputMessage) {
return new ServerHttpRequestDecorator(exchange.getRequest()) {
- @Override
- public HttpHeaders getHeaders() {
- long contentLength = headers.getContentLength();
- HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.putAll(super.getHeaders());
- if (contentLength > 0) {
- httpHeaders.setContentLength(contentLength);
- } else {
- httpHeaders.set(HttpHeaders.TRANSFER_ENCODING, "chunked");
- }
- return httpHeaders;
- }
-
@Override
public Flux<DataBuffer> getBody() {
return outputMessage.getBody();
