Browse Source

http: Use OOP for OutgoingMessage._finish

Sniffing instanceof a child class in the parent class's method
is Doing It Wrong.
isaacs 12 years ago
parent
commit
831de7cbb9
  1. 6
      lib/_http_client.js
  2. 17
      lib/_http_outgoing.js
  3. 7
      lib/_http_server.js

6
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());

17
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');
};

7
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;

Loading…
Cancel
Save