# HG changeset patch # User John "Elwin" Edwards # Date 1338913909 25200 # Node ID 7dd6becf9ce9d15ad7688ebbe1fb54313987b2fb # Parent b5570a594266e74364ae0fb34ddfd58c072a9463 rlgwebd.js: improve MIME types. Respond with the proper MIME type for JSON, and identify HTML as using the UTF-8 charset. diff -r b5570a594266 -r 7dd6becf9ce9 rlgwebd.js --- a/rlgwebd.js Tue Jun 05 09:22:17 2012 -0700 +++ b/rlgwebd.js Tue Jun 05 09:31:49 2012 -0700 @@ -352,7 +352,7 @@ /* 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ "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;