[fix] perf optimization so we have a precompiled regexp

This commit is contained in:
Jarrett Cruger 2014-09-17 07:53:18 -04:00
parent 90d40d6a6a
commit c0a796b3e3

View File

@ -2,6 +2,7 @@ var common = exports,
url = require('url'), url = require('url'),
extend = require('util')._extend; extend = require('util')._extend;
var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
/** /**
* Copies the right headers from `options` and `req` to * Copies the right headers from `options` and `req` to
* `outgoing` which is then used to fire the proxied * `outgoing` which is then used to fire the proxied
@ -53,7 +54,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
if (!outgoing.agent) { if (!outgoing.agent) {
outgoing.headers = outgoing.headers || {}; outgoing.headers = outgoing.headers || {};
if (typeof outgoing.headers.connection !== 'string' if (typeof outgoing.headers.connection !== 'string'
|| ! /(^|,)\s*upgrade\s*($|,)/i.test(outgoing.headers.connection) || ! upgradeHeader.test(outgoing.headers.connection)
) { outgoing.headers.connection = 'close'; } ) { outgoing.headers.connection = 'close'; }
} }