The spec doesn't say anything about the case insensitivity of headers,
and the HTTP spec does say that headers are case insensitive.
Thus, all these forms are valid for saying the same thing:
[ 200, { "Content-Type": "text/plain" }, ["..."]}
[ 200, { "CONTENT-TYPE": "text/plain" }, ["..."]}
[ 200, { "content-type": "text/plain" }, ["..."]}
[ 200, { "Content-type": "text/plain" }, ["..."]}
...
That's alright when it comes to creating the output, but the real issue
is with middleware.
exports.app = function app(env) {
...
}
// Middleware that makes sure all text types have a default
charset=UTF-8 so stuff doesn't default back to Latin1
function UnicodeText(app) {
return function(env) {
var res = app(env);
var ContentType = res[1]["Content-Type"];
if( ContentType &&
ContentType.match(/^(text/[^;]+|application/xhtml+xml)$/) ) {
res[1]["Content-Type"] = ContentType + '; charset=UTF-8';
}
return res;
};
}
exports.development = function(app) {
return Unicode(app);
};
But the problem here, is those headers. How is this piece of middleware
supposed to know what headers to use. Because it's perfectly valid for
the app to use { 'CONTENT-TYPE': 'text/html' } instead.
And we don't have any sort of intermediate processing of the response so
there is no location for implementations to inject a little bit of
header name cleanup in between middleware and other middleware and the app.
--
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
So the HTTP Headers module I ported from the perl version I *think*
gets round this problem, or at least half of it
http://redmine.flusspferd.org/repositories/entry/flusspferd/src/js/http/headers.js#L91
and #L151
But it still doesn't get round it fully, And I'm not sure we (i.e.
using my version) can fully get round it without round-tripping it via
to string and back, or with a __noSuchProperty__ handler (which isn't
possible yet)