Created
June 14, 2018 12:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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