Comparison

plugins/mod_httpserver.lua @ 2772:18d83fd07db1

mod_httpserver: Skip returning a Content-Type when not known (application/octet-stream is not a correct default).
author Waqas Hussain <waqas20@gmail.com>
date Thu, 10 Dec 2009 16:25:50 +0500
parent 2771:c9834f338a4e
child 2773:591c8ae9ae09
comparison
equal deleted inserted replaced
2771:c9834f338a4e 2772:18d83fd07db1
50 local f, err = open(http_base..path, "r"); 50 local f, err = open(http_base..path, "r");
51 if not f then return response_404; end 51 if not f then return response_404; end
52 local data = f:read("*a"); 52 local data = f:read("*a");
53 f:close(); 53 f:close();
54 local ext = path:match("%.([^.]*)$"); 54 local ext = path:match("%.([^.]*)$");
55 local mime = mime_map[ext]; 55 local mime = mime_map[ext]; -- Content-Type should be nil when not known
56 if not mime then 56 module:log("warn", "ext: %s, mime: %s", ext or "(nil)", mime or "(nil)");
57 mime = ext and "application/octet-stream" or "text/html";
58 end
59 module:log("warn", "ext: %s, mime: %s", ext, mime);
60 return { 57 return {
61 headers = { ["Content-Type"] = mime; }; 58 headers = { ["Content-Type"] = mime; };
62 body = data; 59 body = data;
63 }; 60 };
64 end 61 end