Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[fix] Emit header event only if response exists

  • Loading branch information...
commit 0738ad329b20b1f6976aede089040959a9eb48ca 1 parent ce91a78
Pavan Kumar Sunkara pksunkara authored

Showing 1 changed file with 8 additions and 6 deletions. Show diff stats Hide diff stats

  1. +8 6 lib/response-stream.js
14 lib/response-stream.js
@@ -24,7 +24,6 @@ var ResponseStream = module.exports = function (options) {
24 24 this.response = options.response;
25 25
26 26 this._headers = this.headers = this.headers || {};
27   - this._renderHeaders = this.response._renderHeaders;
28 27
29 28 if (options.headers) {
30 29 for (var key in options.headers) {
@@ -49,12 +48,15 @@ var ResponseStream = module.exports = function (options) {
49 48 //
50 49 // Proxy to emit "header" event
51 50 //
52   - this.response._renderHeaders = function () {
53   - if (!self._emittedHeader) {
54   - self._emittedHeader = true;
55   - self.emit('header');
  51 + if (this.response) {
  52 + this._renderHeaders = this.response._renderHeaders;
  53 + this.response._renderHeaders = function () {
  54 + if (!self._emittedHeader) {
  55 + self._emittedHeader = true;
  56 + self.emit('header');
  57 + }
  58 + return self._renderHeaders.call(self.response);
56 59 }
57   - return self._renderHeaders.call(self.response);
58 60 }
59 61 };
60 62

0 comments on commit 0738ad3

Please sign in to comment.
Something went wrong with that request. Please try again.