protected Response addContentPropertiesToResponse(ResponseBuilder response,
                                                      Map<String, String> properties) {
        if (properties != null) {
            // Set Accept-Ranges header
            properties.remove(HttpHeaders.ACCEPT_RANGES);
            response.header(HttpHeaders.ACCEPT_RANGES, HttpHeaders.ACCEPT_RANGES_BYTES);

            // Set Content-Type header
            String contentMimetype = // content-mimetype header
                properties.remove(StorageProvider.PROPERTIES_CONTENT_MIMETYPE);
            String contentType = // Content-Type header
                properties.remove(HttpHeaders.CONTENT_TYPE);
            if (null != contentMimetype && validMimetype(contentMimetype)) {
                response.header(HttpHeaders.CONTENT_TYPE, contentMimetype);
            } else if (null != contentType && validMimetype(contentType)) {
                response.header(HttpHeaders.CONTENT_TYPE, contentType);
            } else {
                response.header(HttpHeaders.CONTENT_TYPE, DEFAULT_MIME);
            }

            // Set Content-Length header
            String contentSize = // content-size header
                properties.remove(StorageProvider.PROPERTIES_CONTENT_SIZE);
            String contentLength = // Content-Length header
                properties.remove(HttpHeaders.CONTENT_LENGTH);
            if (null != contentSize) {
                response.header(HttpHeaders.CONTENT_LENGTH, contentSize);
            } else if (null != contentLength) {
                response.header(HttpHeaders.CONTENT_LENGTH, contentLength);
            }

            // Set Last-Modified header
            String contentModified = // content-modified header
                properties.remove(StorageProvider.PROPERTIES_CONTENT_MODIFIED);
            String lastModified = // Last-Modified header
                properties.remove(HttpHeaders.LAST_MODIFIED);
            if (null != contentModified) {
                response.header(HttpHeaders.LAST_MODIFIED, contentModified);
            } else if (null != lastModified) {
                response.header(HttpHeaders.LAST_MODIFIED, lastModified);
            }

            // Set ETag and Content-MD5 headers
            String contentChecksum = // content-checksum header
                properties.remove(StorageProvider.PROPERTIES_CONTENT_CHECKSUM);
            String contentMdFive = // content-md5 header
                properties.remove(StorageProvider.PROPERTIES_CONTENT_MD5);
            String contentMd5 = // Content-MD5 header
                properties.remove(HttpHeaders.CONTENT_MD5);
            String etag = // ETag header
                properties.remove(HttpHeaders.ETAG);
            if (null != contentChecksum) {
                response.header(HttpHeaders.CONTENT_MD5, contentChecksum);
                response.header(HttpHeaders.ETAG, contentChecksum);
            } else if (null != contentMdFive) {
                response.header(HttpHeaders.CONTENT_MD5, contentMdFive);
                response.header(HttpHeaders.ETAG, contentMdFive);
            } else if (null != contentMd5) {
                response.header(HttpHeaders.CONTENT_MD5, contentMd5);
                response.header(HttpHeaders.ETAG, contentMd5);
            } else if (null != etag) {
                response.header(HttpHeaders.CONTENT_MD5, etag);
                response.header(HttpHeaders.ETAG, etag);
            }

            // Set the remaining property values as headers
            Iterator<String> propertiesNames = properties.keySet().iterator();
            while (propertiesNames.hasNext()) {
                String propertiesName = propertiesNames.next();
                String propertiesValue = properties.get(propertiesName);

                if (propertiesName.equals(HttpHeaders.DATE) ||
                    propertiesName.equals(HttpHeaders.CONNECTION)) {
                    // Ignore this value
                } else if (propertiesName.equals(HttpHeaders.ACCEPT_RANGES) ||
                           propertiesName.equals(HttpHeaders.AGE) ||
                           propertiesName.equals(HttpHeaders.CACHE_CONTROL) ||
                           propertiesName.equals(HttpHeaders.CONTENT_ENCODING) ||
                           propertiesName.equals(HttpHeaders.CONTENT_LANGUAGE) ||
                           propertiesName.equals(HttpHeaders.CONTENT_LOCATION) ||
                           propertiesName.equals(HttpHeaders.CONTENT_RANGE) ||
                           propertiesName.equals(HttpHeaders.EXPIRES) ||
                           propertiesName.equals(HttpHeaders.LOCATION) ||
                           propertiesName.equals(HttpHeaders.PRAGMA) ||
                           propertiesName.equals(HttpHeaders.RETRY_AFTER) ||
                           propertiesName.equals(HttpHeaders.SERVER) ||
                           propertiesName.equals(HttpHeaders.TRANSFER_ENCODING) ||
                           propertiesName.equals(HttpHeaders.UPGRADE) ||
                           propertiesName.equals(HttpHeaders.WARNING)) {
                    // Pass through as a standard http header
                    response.header(propertiesName, propertiesValue);
                } else {
                    // Custom header, append prefix
                    response.header(HEADER_PREFIX + propertiesName, propertiesValue);
                }
            }
        }
        return response.build();
    }
protected Response addContentPropertiesToResponse ( ResponseBuilder response , Map < String , String > properties ) { if ( properties != null ) { properties . remove ( HttpHeaders . ACCEPT_RANGES ) ; response . header ( HttpHeaders . ACCEPT_RANGES , HttpHeaders . ACCEPT_RANGES_BYTES ) ; String contentMimetype = properties . remove ( StorageProvider . PROPERTIES_CONTENT_MIMETYPE ) ; String contentType = properties . remove ( HttpHeaders . CONTENT_TYPE ) ; if ( null != contentMimetype && validMimetype ( contentMimetype ) ) { response . header ( HttpHeaders . CONTENT_TYPE , contentMimetype ) ; } else if ( null != contentType && validMimetype ( contentType ) ) { response . header ( HttpHeaders . CONTENT_TYPE , contentType ) ; } else { response . header ( HttpHeaders . CONTENT_TYPE , DEFAULT_MIME ) ; } String contentSize = properties . remove ( StorageProvider . PROPERTIES_CONTENT_SIZE ) ; String contentLength = properties . remove ( HttpHeaders . CONTENT_LENGTH ) ; if ( null != contentSize ) { response . header ( HttpHeaders . CONTENT_LENGTH , contentSize ) ; } else if ( null != contentLength ) { response . header ( HttpHeaders . CONTENT_LENGTH , contentLength ) ; } String contentModified = properties . remove ( StorageProvider . PROPERTIES_CONTENT_MODIFIED ) ; String lastModified = properties . remove ( HttpHeaders . LAST_MODIFIED ) ; if ( null != contentModified ) { response . header ( HttpHeaders . LAST_MODIFIED , contentModified ) ; } else if ( null != lastModified ) { response . header ( HttpHeaders . LAST_MODIFIED , lastModified ) ; } String contentChecksum = properties . remove ( StorageProvider . PROPERTIES_CONTENT_CHECKSUM ) ; String contentMdFive = properties . remove ( StorageProvider . PROPERTIES_CONTENT_MD5 ) ; String contentMd5 = properties . remove ( HttpHeaders . CONTENT_MD5 ) ; String etag = properties . remove ( HttpHeaders . ETAG ) ; if ( null != contentChecksum ) { response . header ( HttpHeaders . CONTENT_MD5 , contentChecksum ) ; response . header ( HttpHeaders . ETAG , contentChecksum ) ; } else if ( null != contentMdFive ) { response . header ( HttpHeaders . CONTENT_MD5 , contentMdFive ) ; response . header ( HttpHeaders . ETAG , contentMdFive ) ; } else if ( null != contentMd5 ) { response . header ( HttpHeaders . CONTENT_MD5 , contentMd5 ) ; response . header ( HttpHeaders . ETAG , contentMd5 ) ; } else if ( null != etag ) { response . header ( HttpHeaders . CONTENT_MD5 , etag ) ; response . header ( HttpHeaders . ETAG , etag ) ; } Iterator < String > propertiesNames = properties . keySet ( ) . iterator ( ) ; while ( propertiesNames . hasNext ( ) ) { String propertiesName = propertiesNames . next ( ) ; String propertiesValue = properties . get ( propertiesName ) ; if ( propertiesName . equals ( HttpHeaders . DATE ) || propertiesName . equals ( HttpHeaders . CONNECTION ) ) { } else if ( propertiesName . equals ( HttpHeaders . ACCEPT_RANGES ) || propertiesName . equals ( HttpHeaders . AGE ) || propertiesName . equals ( HttpHeaders . CACHE_CONTROL ) || propertiesName . equals ( HttpHeaders . CONTENT_ENCODING ) || propertiesName . equals ( HttpHeaders . CONTENT_LANGUAGE ) || propertiesName . equals ( HttpHeaders . CONTENT_LOCATION ) || propertiesName . equals ( HttpHeaders . CONTENT_RANGE ) || propertiesName . equals ( HttpHeaders . EXPIRES ) || propertiesName . equals ( HttpHeaders . LOCATION ) || propertiesName . equals ( HttpHeaders . PRAGMA ) || propertiesName . equals ( HttpHeaders . RETRY_AFTER ) || propertiesName . equals ( HttpHeaders . SERVER ) || propertiesName . equals ( HttpHeaders . TRANSFER_ENCODING ) || propertiesName . equals ( HttpHeaders . UPGRADE ) || propertiesName . equals ( HttpHeaders . WARNING ) ) { response . header ( propertiesName , propertiesValue ) ; } else { response . header ( HEADER_PREFIX + propertiesName , propertiesValue ) ; } } } return response . build ( ) ; }
Adds the properties of a content item as header values to the response.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
for specifics on particular headers.