Skip to content

Allow disabling HTTP range support [SPR-13660] #18235

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions