Skip to content
Snippets Groups Projects
Commit cc9491da authored by Martin Nilsson's avatar Martin Nilsson
Browse files

Use MIME.ext_to_media_type instead of private database.

Rev: lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/module.pmod:1.9
parent 6d8e74bc
No related branches found
No related tags found
No related merge requests found
...@@ -41,32 +41,11 @@ mapping(string:string|array(string)) ...@@ -41,32 +41,11 @@ mapping(string:string|array(string))
//! method string filename_to_type(string filename) //! method string filename_to_type(string filename)
//! method string extension_to_type(string extension) //! method string extension_to_type(string extension)
//! Looks up the file extension in a table to return //! Looks up the file extension in a table to return
//! a suitable MIME type. The table is located in the //! a suitable MIME type.
//! [...]pike/lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/extensions.txt
//! file.
mapping extensions=0;
string extension_to_type(string extension) string extension_to_type(string extension)
{ {
if (!extensions) return MIME.ext_to_media_type(extension) || "application/octet-stream";
{
Stdio.File f=Stdio.FILE(
combine_path(__FILE__,"..","extensions.txt"),"r");
mapping res=([]);
while (array a=f->ngets(1000))
foreach (a,string l)
if (sscanf(l,"%*[ \t]%[^ \t]%*[ \t]%[^ \t]",
string ext,string type)==4 &&
ext!="" && ext[0]!='#')
res[ext]=type;
extensions=res;
}
return extensions[extension] || "application/octet-stream";
} }
string filename_to_type(string filename) string filename_to_type(string filename)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment