From 831de7cbb911ebae58237babed22a672dc6a9da0 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 30 May 2013 16:08:03 -0700 Subject: [PATCH] http: Use OOP for OutgoingMessage._finish Sniffing instanceof a child class in the parent class's method is Doing It Wrong. --- lib/_http_client.js | 6 ++++++ lib/_http_outgoing.js | 17 ----------------- lib/_http_server.js | 7 +++++++ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 0bc78ab1a4..276c6407a4 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -133,6 +133,12 @@ util.inherits(ClientRequest, OutgoingMessage); exports.ClientRequest = ClientRequest; +ClientRequest.prototype._finish = function() { + DTRACE_HTTP_CLIENT_REQUEST(this, this.connection); + COUNTER_HTTP_CLIENT_REQUEST(); + OutgoingMessage.prototype._finish.call(this); +}; + ClientRequest.prototype._implicitHeader = function() { this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n', this._renderHeaders()); diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 66ed47a9bf..397b430c2f 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -515,25 +515,8 @@ OutgoingMessage.prototype.end = function(data, encoding) { }; -var ServerResponse, ClientRequest; - OutgoingMessage.prototype._finish = function() { assert(this.connection); - - if (!ServerResponse) - ServerResponse = require('_http_server').ServerResponse; - - if (!ClientRequest) - ClientRequest = require('_http_client').ClientRequest; - - if (this instanceof ServerResponse) { - DTRACE_HTTP_SERVER_RESPONSE(this.connection); - COUNTER_HTTP_SERVER_RESPONSE(); - } else { - assert(this instanceof ClientRequest); - DTRACE_HTTP_CLIENT_REQUEST(this, this.connection); - COUNTER_HTTP_CLIENT_REQUEST(); - } this.emit('finish'); }; diff --git a/lib/_http_server.js b/lib/_http_server.js index 64e49c4cd0..f6cfa3543c 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -111,6 +111,13 @@ function ServerResponse(req) { } util.inherits(ServerResponse, OutgoingMessage); +ServerResponse.prototype._finish = function() { + DTRACE_HTTP_SERVER_RESPONSE(this.connection); + COUNTER_HTTP_SERVER_RESPONSE(); + OutgoingMessage.prototype._finish.call(this); +}; + + exports.ServerResponse = ServerResponse;