Skip to content

Loading…

Send 404 errors in a way all browsers decode right #875

Merged
merged 1 commit into from

3 participants

@johan

No description provided.

@jonathanong

i want to merge this, but tj said

looks good, I'd remove the

 so tools like curl don't get less readable output

@johan johan Don't escape text/plain as HTML in default error handlers
Before: `Cannot GET http://localhost/?a=b&c=d`
After:  `Cannot GET http://localhost/?a=b&c=d`
e14f292
@johan

Thanks for the reminder. Reworked as requested and rebased to current master.

@tj tj merged commit 9a78e75 into senchalabs:master

1 check passed

Details default The Travis CI build passed
@johan johan deleted the johan:html-404 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 15, 2013
  1. @johan

    Don't escape text/plain as HTML in default error handlers

    johan committed
    Before: `Cannot GET http://localhost/?a=b&c=d`
    After:  `Cannot GET http://localhost/?a=b&c=d`
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/proto.js
View
6 lib/proto.js
@@ -1,4 +1,3 @@
-
/*!
* Connect - HTTPServer
* Copyright(c) 2010 Sencha Inc.
@@ -139,18 +138,19 @@ app.handle = function(req, res, out) {
var msg = 'production' == env
? http.STATUS_CODES[res.statusCode]
: err.stack || err.toString();
+ msg = utils.escape(msg);
// log to stderr in a non-test env
if ('test' != env) console.error(err.stack || err.toString());
if (res.headerSent) return req.socket.destroy();
- res.setHeader('Content-Type', 'text/plain');
+ res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', Buffer.byteLength(msg));
if ('HEAD' == req.method) return res.end();
res.end(msg);
} else {
debug('default 404');
res.statusCode = 404;
- res.setHeader('Content-Type', 'text/plain');
+ res.setHeader('Content-Type', 'text/html');
if ('HEAD' == req.method) return res.end();
res.end('Cannot ' + utils.escape(req.method) + ' ' + utils.escape(req.originalUrl));
}
Something went wrong with that request. Please try again.