Software /
code /
prosody
Changeset
2761:5d3ad9a6b3be
net.httpserver: Quick fix to set the correct Content-Type on simple (string) responses, for a few known types
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 02 Dec 2009 18:02:47 +0000 |
parents | 2760:604db849f111 |
children | 2762:2bddf8b766f7 |
files | net/httpserver.lua |
diffstat | 1 files changed, 6 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/net/httpserver.lua Sat Nov 21 13:47:45 2009 +0000 +++ b/net/httpserver.lua Wed Dec 02 18:02:47 2009 +0000 @@ -23,6 +23,9 @@ 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 @@ 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");