Closed
Description
Kevin McLaughlin opened SPR-13660 and commented
Follow up from #15431.
There should be a way to easily disable Range support in ResourceHttpRequestHandler.
https://tools.ietf.org/html/rfc7233
Filter we are using to do this (ugly):
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws
IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpServletRequest httpRequest = (HttpServletRequest) request;
httpResponse.setHeader(HttpHeaders.ACCEPT_RANGES, "none");
// Wrapped response which ignores requests to set Accept-Ranges header.
HttpServletResponse wrappedResponse = new HttpServletResponseWrapper(httpResponse) {
@Override
public void setHeader(String name, String value) {
if (!HttpHeaders.ACCEPT_RANGES.equals(name)) {
super.setHeader(name, value);
} else {
log.trace("Ignoring attempt to set {} to {}", name, value);
}
}
};
// Wrapped request which hides Range header so Spring doesn't try to fulfill a Range
// request.
HttpServletRequest wrappedRequest = new HttpServletRequestWrapper(httpRequest) {
/**
* See ResourceHttpRequestHandler.java in spring. This could break if the condition checking
* if this header exists changes to use a different method on request.
*/
@Override
public String getHeader(String name) {
return HttpHeaders.RANGE.equals(name) ? null : super.getHeader(name);
}
};
chain.doFilter(wrappedRequest, wrappedResponse);
}
Affects: 4.2.2
Issue Links:
- Add support for http byte-range requests [SPR-10805] #15431 Add support for http byte-range requests
- HTTP Range requests hang on large file in nested jar [SPR-13661] #18236 HTTP Range requests hang on large file in nested jar