3 var http = require('http');
4 var useragent = require('useragent');
6 var ServerResponsePrototype = http.ServerResponse.prototype;
7 var IncomingMessagePrototype = http.IncomingMessage.prototype;
9 /* Monkey patch onto the response */
11 * This is needed as connect/express attempt to be too smart for their own good behind proxies (like NGINX) and convert relative URLS into absolute URLS. Unfortunately behind a proxy the URL will proably we wrong.
12 * TODO: raise this as a bug in express
14 ServerResponsePrototype.relativeRedirect = function(status, url) {
23 // Support text/{plain,html} by default
24 if (req.accepts('html')) {
27 http.STATUS_CODES[status] +
28 '. Redirecting to <a href="' +
33 this.header('Content-Type', 'text/html');
35 body = http.STATUS_CODES[status] + '. Redirecting to ' + url;
36 this.header('Content-Type', 'text/plain');
40 this.statusCode = status;
41 this.header('Location', url);
45 IncomingMessagePrototype.getParsedUserAgent = function() {
46 if (this._parsedUserAgent) {
47 return this._parsedUserAgent;
50 var parsedUserAgent = useragent.parse(this.headers['user-agent']);
51 this._parsedUserAgent = parsedUserAgent;
52 return parsedUserAgent;