-
Notifications
You must be signed in to change notification settings - Fork 161
Derive media content types from file content, not the request #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
|
|
||
| import org.apache.commons.logging.Log; | ||
| import org.apache.commons.logging.LogFactory; | ||
| import org.apache.roller.weblogger.util.MediaTypePolicy; | ||
| import org.apache.roller.weblogger.WebloggerException; | ||
| import org.apache.roller.weblogger.business.MediaFileManager; | ||
| import org.apache.roller.weblogger.business.WebloggerFactory; | ||
|
|
@@ -125,7 +126,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) | |
| } | ||
|
|
||
| // if not from theme then see if resource is in weblog's upload dir | ||
| boolean fromUploadedMedia = false; | ||
| if (resourceStream == null) { | ||
| fromUploadedMedia = true; | ||
| try { | ||
| MediaFileManager mmgr = WebloggerFactory.getWeblogger() | ||
| .getMediaFileManager(); | ||
|
|
@@ -159,8 +162,19 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) | |
| } | ||
|
|
||
| // set the content type based on whatever is in our web.xml mime defs | ||
| response.setContentType(this.context.getMimeType(resourceRequest | ||
| .getResourcePath())); | ||
| String resourceType = MediaTypePolicy.typeFromName( | ||
| resourceRequest.getResourcePath(), this.context::getMimeType); | ||
| if (fromUploadedMedia) { | ||
| // Uploaded through the media library, so it is governed by the | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This branch is also where customized-theme resources land: |
||
| // same policy as any other media response. | ||
| MediaTypePolicy.applyResponseHeaders(response, resourceType, | ||
| resourceRequest.getResourcePath()); | ||
| } else { | ||
| // A theme resource: authored as part of the theme and served as | ||
| // the type the theme intends, but never re-typed by the browser. | ||
| response.setHeader("X-Content-Type-Options", "nosniff"); | ||
| response.setContentType(resourceType); | ||
| } | ||
|
|
||
| try { | ||
| // ok, lets serve up the file | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context.getMimeType()returnsnullfor extensions not mapped inweb.xml/the container, andapplyResponseHeadersturnsnullinto an octet-stream attachment. On mastersetContentType(null)left the type unset and the browser could still display the file; now any unmapped (or uppercase, on a case-sensitive container) extension downloads in the theme preview.