Allow explicit Content-Type while serving file #51

Closed
wants to merge 1 commit into
from

2 participants

@Motiejus

When using Req:serve_file/3 with Content-Type ExtraHeader, it is being
overwritten by mochiweb_util:guess_mime/1. This patch makes it check if
Content-Type is not defined before serving the file. If defined, leave
Content-Type intact.

@Motiejus Motiejus Allow explicit Content-Type while serving file
When using Req:serve_file/3 with Content-Type ExtraHeader, it is being
overwritten by mochiweb_util:guess_mime/1. This patch makes it check if
Content-Type is not defined before serving the file. If defined, leave
Content-Type intact.
cd17eb1
@dreid
Mochi Media, Inc. member

So I guess there are 3 use cases for this:

  1. You actually want all files in the given path to be served with this content type regardless of their actual type.
  2. You want to override a type a definition in mochiweb_mime while using the guessed types for all other files.
  3. You want to add a currently unsupported type to mochiweb_mime using the guessed types for all other files.

The current patch only really supports use case number 1.

To support the 2nd and 3rd use cases you'd also need to change mochiweb_util:guess_mime to have a 2 arity version that took a proplist of the form [{default | Extension::string(), MimeType::string()}] Where Extension can be looked up before the call into mochiweb_mime and default can be used when mochiweb_mime:from_extension returns undefined (with default defaulting to "text/plain" as it currently does.

A 4 arity version of serve_file (and corresponding 3 arity version of maybe_serve_file) that takes an option list with a mime_overrides option would finish this off nicely.

@Motiejus

Thank you for comments.

I just realized this feature is not necessary for me, since I can simply change the file extension.

Closing.

@Motiejus Motiejus closed this Jun 29, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment