aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-12-02 18:02:47 +0000
committerMatthew Wild <mwild1@gmail.com>2009-12-02 18:02:47 +0000
commitb74d2847c0e893c9f189c47a184f63989b4108ab (patch)
treef8d646255a1861a646d9af90a2f8aa38b2e31171
parentcd82ebe27d0053834d644f6f8b45b445552abf8d (diff)
downloadprosody-b74d2847c0e893c9f189c47a184f63989b4108ab.tar.gz
prosody-b74d2847c0e893c9f189c47a184f63989b4108ab.zip
net.httpserver: Quick fix to set the correct Content-Type on simple (string) responses, for a few known types
-rw-r--r--net/httpserver.lua6
1 files changed, 6 insertions, 0 deletions
diff --git a/net/httpserver.lua b/net/httpserver.lua
index ddb4475c..7366351e 100644
--- a/net/httpserver.lua
+++ b/net/httpserver.lua
@@ -23,6 +23,9 @@ local urlencode = function (s) return s and (s:gsub("%W", function (c) return st
local log = require "util.logger".init("httpserver");
+-- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?)
+local mime_map = { html = "text/html", txt = "plain/text; charset=utf-8", js = "text/javascript" };
+
local http_servers = {};
module "httpserver"
@@ -65,6 +68,9 @@ local function send_response(request, response)
resp = { "HTTP/1.0 200 OK\r\n" };
t_insert(resp, "Connection: close\r\n");
+ t_insert(resp, "Content-Type: ");
+ t_insert(resp, mime_map[request.url.path:match("%.(%w+)")] or "application/octet-stream");
+ t_insert(resp, "\r\n");
t_insert(resp, "Content-Length: ");
t_insert(resp, #response);
t_insert(resp, "\r\n\r\n");