Permalink
Browse files

[fix] Emit header event only if response exists

  • Loading branch information...
1 parent ce91a78 commit 0738ad329b20b1f6976aede089040959a9eb48ca @pksunkara pksunkara committed Mar 25, 2012
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/response-stream.js
View
@@ -24,7 +24,6 @@ var ResponseStream = module.exports = function (options) {
this.response = options.response;
this._headers = this.headers = this.headers || {};
- this._renderHeaders = this.response._renderHeaders;
if (options.headers) {
for (var key in options.headers) {
@@ -49,12 +48,15 @@ var ResponseStream = module.exports = function (options) {
//
// Proxy to emit "header" event
//
- this.response._renderHeaders = function () {
- if (!self._emittedHeader) {
- self._emittedHeader = true;
- self.emit('header');
+ if (this.response) {
+ this._renderHeaders = this.response._renderHeaders;
+ this.response._renderHeaders = function () {
+ if (!self._emittedHeader) {
+ self._emittedHeader = true;
+ self.emit('header');
+ }
+ return self._renderHeaders.call(self.response);
}
- return self._renderHeaders.call(self.response);
}
};

0 comments on commit 0738ad3

Please sign in to comment.