in wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java [766:881]
protected void setResponseHeaders(final ResourceResponse resourceResponse,
final Attributes attributes)
{
Response response = attributes.getResponse();
if (response instanceof WebResponse)
{
WebResponse webResponse = (WebResponse)response;
// 1. Last Modified
Instant lastModified = resourceResponse.getLastModified();
if (lastModified != null)
{
webResponse.setLastModifiedTime(lastModified);
}
// 2. Caching
configureCache(resourceResponse, attributes);
if (resourceResponse.getErrorCode() != null)
{
webResponse.sendError(resourceResponse.getErrorCode(),
resourceResponse.getErrorMessage());
return;
}
if (resourceResponse.getStatusCode() != null)
{
webResponse.setStatus(resourceResponse.getStatusCode());
}
if (!resourceResponse.dataNeedsToBeWritten(attributes))
{
webResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
// 3. Content Disposition
String fileName = resourceResponse.getFileName();
ContentDisposition disposition = resourceResponse.getContentDisposition();
if (ContentDisposition.ATTACHMENT == disposition)
{
webResponse.setAttachmentHeader(fileName);
}
else if (ContentDisposition.INLINE == disposition)
{
webResponse.setInlineHeader(fileName);
}
// 4. Mime Type (+ encoding)
String mimeType = resourceResponse.getContentType();
if (mimeType != null)
{
final String encoding = resourceResponse.getTextEncoding();
if (encoding == null)
{
webResponse.setContentType(mimeType);
}
else
{
webResponse.setContentType(mimeType + "; charset=" + encoding);
}
}
// 5. Accept Range
ContentRangeType acceptRange = resourceResponse.getAcceptRange();
if (acceptRange != null)
{
webResponse.setAcceptRange(acceptRange.getTypeName());
}
long contentLength = resourceResponse.getContentLength();
boolean contentRangeApplied = false;
// 6. Content Range
// for more information take a look here:
// http://stackoverflow.com/questions/8293687/sample-http-range-request-session
// if the content range header has been set directly
// to the resource response use it otherwise calculate it
String contentRange = resourceResponse.getContentRange();
if (contentRange != null)
{
webResponse.setContentRange(contentRange);
}
else
{
// content length has to be set otherwise the content range header can not be
// calculated - accept range must be set to bytes - others are not supported at the
// moment
if (contentLength != -1 && ContentRangeType.BYTES.equals(acceptRange))
{
contentRangeApplied = setResponseContentRangeHeaderFields(webResponse,
attributes, contentLength);
}
}
// 7. Content Length
if (contentLength != -1 && !contentRangeApplied)
{
webResponse.setContentLength(contentLength);
}
// add custom headers and values
final HttpHeaderCollection headers = resourceResponse.getHeaders();
for (String name : headers.getHeaderNames())
{
checkHeaderAccess(name);
for (String value : headers.getHeaderValues(name))
{
webResponse.addHeader(name, value);
}
}
}
}