protected void setRespondCommonHeaders( Response response, Resource resource, Response.Status status, Auth auth) { response.setStatus(status); response.setNonStandardHeader("Server", "milton.io-" + miltonVerson); response.setDateHeader(new Date()); response.setNonStandardHeader("Accept-Ranges", "bytes"); String etag = eTagGenerator.generateEtag(resource); if (etag != null) { response.setEtag(etag); } }
@Override public void respondNotModified(GetableResource resource, Response response, Request request) { log.trace("respondNotModified"); response.setStatus(Response.Status.SC_NOT_MODIFIED); response.setDateHeader(new Date()); String etag = eTagGenerator.generateEtag(resource); if (etag != null) { response.setEtag(etag); } // Note that we use a simpler modified date handling here then when // responding with content, because in a not-modified situation the // modified date MUST be that of the actual resource Date modDate = resource.getModifiedDate(); response.setLastModifiedHeader(modDate); cacheControlHelper.setCacheControl(resource, response, request.getAuthorization()); }
@Override public void respondPartialContent( GetableResource resource, Response response, Request request, Map<String, String> params, Range range) throws NotAuthorizedException, BadRequestException, NotFoundException { log.debug("respondPartialContent: " + range.getStart() + " - " + range.getFinish()); response.setStatus(Response.Status.SC_PARTIAL_CONTENT); long st = range.getStart() == null ? 0 : range.getStart(); long fn; Long cl = resource.getContentLength(); if (range.getFinish() == null) { if (cl != null) { fn = cl.longValue() - 1; // position is one less then length } else { log.warn( "Couldnt calculate range end position because the resource is not reporting a content length, and no end position was requested by the client: " + resource.getName() + " - " + resource.getClass()); fn = -1; } } else { fn = range.getFinish(); } response.setContentRangeHeader(st, fn, cl); long contentLength = fn - st + 1; response.setContentLengthHeader(contentLength); response.setDateHeader(new Date()); String etag = eTagGenerator.generateEtag(resource); if (etag != null) { response.setEtag(etag); } String acc = request.getAcceptHeader(); String ct = resource.getContentType(acc); if (ct != null) { response.setContentTypeHeader(ct); } response.setEntity(new GetableResourceEntity(resource, range, params, ct)); }
@Override public String generateEtag(Resource r) { return eTagGenerator.generateEtag(r); }