Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Created June 14, 2018 12:30
Show Gist options
  • Save lovasoa/00d924503f681c45b44a3fc8e72e8239 to your computer and use it in GitHub Desktop.
Save lovasoa/00d924503f681c45b44a3fc8e72e8239 to your computer and use it in GitHub Desktop.
Small node server to help testing how a client handles invalid or conflicting encodings. Launch it, then visit http://localhost:8000/?responseText=héhé&htmlCharset=iso-8859-1&headerCharset=windows-1251
var http = require('http');
var uparse = require('url').parse;
http.createServer(function ({url}, res) {
const {headerCharset, responseText, htmlCharset} = uparse(url, true).query;
const ctype = 'text/html' + (headerCharset ? '; charset=' + headerCharset : '');
res.writeHead(200, {'Content-Type': ctype});
const meta = htmlCharset ? `<meta charset="${htmlCharset}">` : ``;
res.end(`<!doctype html>
<html>
<head>
${meta}
</head>
<body>${responseText}</body>
</html>`);
}).listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment