Permalink
Browse files

[fix] Emit header event when rendering headers, Fixes #21

  • Loading branch information...
pksunkara committed Mar 25, 2012
1 parent 6c093d1 commit ce91a7809939daf3e3996406f001538a3152df61
Showing with 17 additions and 2 deletions.
  1. +1 −0 lib/request-stream.js
  2. +16 −2 lib/response-stream.js
View
@@ -33,6 +33,7 @@ RequestStream.prototype.pipeRequest = function (source) {
this.method = source.method;
this.httpVersion = source.httpVersion;
this.setEncoding = source.setEncoding;
+ this.connection = source.connection;
if (source.query) {
this.query = source.query;
View
@@ -22,7 +22,10 @@ var ResponseStream = module.exports = function (options) {
this.writeable = true;
this.response = options.response;
-
+
+ this._headers = this.headers = this.headers || {};
+ this._renderHeaders = this.response._renderHeaders;
+
if (options.headers) {
for (var key in options.headers) {
this.response.setHeader(key, options.headers[key]);
@@ -42,6 +45,17 @@ var ResponseStream = module.exports = function (options) {
enumerable: true,
configurable: true
});
+
+ //
+ // Proxy to emit "header" event
+ //
+ this.response._renderHeaders = function () {
+ if (!self._emittedHeader) {
+ self._emittedHeader = true;
+ self.emit('header');
+ }
+ return self._renderHeaders.call(self.response);
+ }
};
util.inherits(ResponseStream, HttpStream);
@@ -60,7 +74,7 @@ ResponseStream.prototype.writeHead = function (statusCode, headers) {
// Create pass-thru for the necessary
// `http.ServerResponse` methods.
//
-['setHeader', 'getHeader', 'removeHeader', 'addTrailers'].forEach(function (method) {
+['setHeader', 'getHeader', 'removeHeader', '_implicitHeader', 'addTrailers'].forEach(function (method) {
ResponseStream.prototype[method] = function () {
return this.response[method].apply(this.response, arguments);
};

0 comments on commit ce91a78

Please sign in to comment.