http: don't slice unless necessary

The incoming Buffer was being sliced just to possibly not be used.
Instead place the .slice inside the conditional to not be created unless
necessary.
This commit is contained in:
Trevor Norris 2013-05-15 14:58:14 -07:00
parent f0d80d7db0
commit 88333f7ace

View File

@ -352,11 +352,10 @@ function connectionListener(socket) {
parser.finish();
freeParser(parser, req);
// This is start + byteParsed
var bodyHead = d.slice(start + bytesParsed, end);
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
if (EventEmitter.listenerCount(self, eventName) > 0) {
// This is start + byteParsed
var bodyHead = d.slice(start + bytesParsed, end);
self.emit(eventName, req, req.socket, bodyHead);
} else {
// Got upgrade header or CONNECT method, but have no handler.