Allow Resource to add headers for range requests

Closes gh-25976
This commit is contained in:
Rossen Stoyanchev
2020-10-27 10:15:56 +00:00
parent 20fe1bcd99
commit f02a2bef8f
3 changed files with 37 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -352,15 +352,14 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
// Check the media type for the resource
MediaType mediaType = MediaTypeFactory.getMediaType(resource).orElse(null);
setHeaders(exchange, resource, mediaType);
// Content phase
if (HttpMethod.HEAD.matches(exchange.getRequest().getMethodValue())) {
setHeaders(exchange, resource, mediaType);
exchange.getResponse().getHeaders().set(HttpHeaders.ACCEPT_RANGES, "bytes");
return Mono.empty();
}
setHeaders(exchange, resource, mediaType);
ResourceHttpMessageWriter writer = getResourceHttpMessageWriter();
Assert.state(writer != null, "No ResourceHttpMessageWriter");
return writer.write(Mono.just(resource),
@@ -535,6 +534,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
if (mediaType != null) {
headers.setContentType(mediaType);
}
if (resource instanceof HttpResource) {
HttpHeaders resourceHeaders = ((HttpResource) resource).getResponseHeaders();
exchange.getResponse().getHeaders().putAll(resourceHeaders);