Example usage for org.springframework.http HttpHeaders ACCEPT_RANGES

List of usage examples for org.springframework.http HttpHeaders ACCEPT_RANGES

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders ACCEPT_RANGES.

Prototype

String ACCEPT_RANGES

To view the source code for org.springframework.http HttpHeaders ACCEPT_RANGES.

Click Source Link

Document

The HTTP Accept-Ranges header field name.

Usage

From source file:org.springframework.web.servlet.resource.ResourceHttpRequestHandler.java

/**
 * Set headers on the given servlet response.
 * Called for GET requests as well as HEAD requests.
 * @param response current servlet response
 * @param resource the identified resource (never {@code null})
 * @param mediaType the resource's media type (never {@code null})
 * @throws IOException in case of errors while setting the headers
 *//*from   w  w  w .  jav  a 2  s. com*/
protected void setHeaders(HttpServletResponse response, Resource resource, @Nullable MediaType mediaType)
        throws IOException {

    long length = resource.contentLength();
    if (length > Integer.MAX_VALUE) {
        response.setContentLengthLong(length);
    } else {
        response.setContentLength((int) length);
    }

    if (mediaType != null) {
        response.setContentType(mediaType.toString());
    }
    if (resource instanceof HttpResource) {
        HttpHeaders resourceHeaders = ((HttpResource) resource).getResponseHeaders();
        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");
}