From 37e64470941c8d04053587cf60da8734c71d2d21 Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Tue, 5 Jun 2012 09:31:49 -0700 Subject: [PATCH] rlgwebd.js: improve MIME types. Respond with the proper MIME type for JSON, and identify HTML as using the UTF-8 charset. --- rlgwebd.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rlgwebd.js b/rlgwebd.js index 3663a7c..e9602ca 100755 --- a/rlgwebd.js +++ b/rlgwebd.js @@ -352,7 +352,7 @@ function login(req, res, formdata) { /* Technically there's a race condition for the "lock"file, but since * it requires the user deliberately starting two games at similar times, * it's not too serious. We can't get O_EXCL in Node anyway. */ - res.writeHead(200, {'Content-Type': 'text/plain'}); + res.writeHead(200, {'Content-Type': 'application/json'}); var reply = {"t": "l", "id": nsession.sessid, "w": nsession.w, "h": nsession.h}; res.write(JSON.stringify(reply)); @@ -445,7 +445,7 @@ function register(req, res, formdata) { tslog("sqlickrypt register failed with code %d", code); } else { - res.writeHead(200, {'Content-Type': 'text/plain'}); + res.writeHead(200, {'Content-Type': 'application/json'}); var reply = {"t": "r", "d": uname}; res.write(JSON.stringify(reply)); res.end(); @@ -465,7 +465,7 @@ function logout(term, res) { return; } term.close(); - var resheaders = {'Content-Type': 'text/plain'}; + var resheaders = {'Content-Type': 'application/json'}; res.writeHead(200, resheaders); res.write(JSON.stringify({"t": "q"})); res.end(); @@ -495,7 +495,7 @@ function serveStatic(req, res, fname) { path.exists(realname, function (exists) { var resheaders = {}; if (!exists || !extension || extension == ".html") - resheaders["Content-Type"] = "text/html"; + resheaders["Content-Type"] = "text/html; charset=utf-8"; else if (extension == ".png") resheaders["Content-Type"] = "image/png"; else if (extension == ".css") @@ -549,7 +549,7 @@ function readFeed(res, term) { reply.n = term.nsend++; reply.d = result.toString("hex"); } - res.writeHead(200, { "Content-Type": "text/plain" }); + res.writeHead(200, { "Content-Type": "application/json" }); res.write(JSON.stringify(reply)); res.end(); } @@ -563,7 +563,7 @@ var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", "Server shutting down" ]; function sendError(res, ecode, msg) { - res.writeHead(200, { "Content-Type": "text/plain" }); + res.writeHead(200, { "Content-Type": "application/json" }); var edict = {"t": "E"}; if (!(ecode < errorcodes.length && ecode > 0)) ecode = 0;