Browse Source

Expose all HttpResource header values (even if commonly not multi-value)

Issue: SPR-14264
pull/1601/merge
Juergen Hoeller 7 years ago
parent
commit
27bbb73583
  1. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java
  2. 19
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java
  3. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

3
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java

@ -158,7 +158,7 @@ public class GzipResourceResolver extends AbstractResourceResolver { @@ -158,7 +158,7 @@ public class GzipResourceResolver extends AbstractResourceResolver {
@Override
public HttpHeaders getResponseHeaders() {
HttpHeaders headers;
if(this.original instanceof HttpResource) {
if (this.original instanceof HttpResource) {
headers = ((HttpResource) this.original).getResponseHeaders();
}
else {
@ -167,7 +167,6 @@ public class GzipResourceResolver extends AbstractResourceResolver { @@ -167,7 +167,6 @@ public class GzipResourceResolver extends AbstractResourceResolver {
headers.add(HttpHeaders.CONTENT_ENCODING, "gzip");
return headers;
}
}
}

19
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

@ -493,8 +493,8 @@ public class ResourceHttpRequestHandler extends WebContentGenerator @@ -493,8 +493,8 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
try {
List<HttpRange> httpRanges = inputMessage.getHeaders().getRange();
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
this.resourceRegionHttpMessageConverter.write(
HttpRange.toResourceRegions(httpRanges, resource), mediaType, outputMessage);
this.resourceRegionHttpMessageConverter.write(
HttpRange.toResourceRegions(httpRanges, resource), mediaType, outputMessage);
}
catch (IllegalArgumentException ex) {
response.setHeader("Content-Range", "bytes */" + resource.contentLength());
@ -654,8 +654,19 @@ public class ResourceHttpRequestHandler extends WebContentGenerator @@ -654,8 +654,19 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
}
if (resource instanceof HttpResource) {
HttpHeaders resourceHeaders = ((HttpResource) resource).getResponseHeaders();
resourceHeaders.toSingleValueMap().entrySet()
.stream().forEach(entry -> response.setHeader(entry.getKey(), entry.getValue()));
for (Map.Entry<String, List<String>> entry : resourceHeaders.entrySet()) {
String headerName = entry.getKey();
boolean first = true;
for (String headerValue : entry.getValue()) {
if (first) {
response.setHeader(headerName, headerValue);
}
else {
response.addHeader(headerName, headerValue);
}
first = false;
}
}
}
response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes");
}

3
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

@ -328,7 +328,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { @@ -328,7 +328,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
@Override
public HttpHeaders getResponseHeaders() {
HttpHeaders headers;
if(this.original instanceof HttpResource) {
if (this.original instanceof HttpResource) {
headers = ((HttpResource) this.original).getResponseHeaders();
}
else {
@ -337,7 +337,6 @@ public class VersionResourceResolver extends AbstractResourceResolver { @@ -337,7 +337,6 @@ public class VersionResourceResolver extends AbstractResourceResolver {
headers.setETag("\"" + this.version + "\"");
return headers;
}
}
}

Loading…
Cancel
Save