Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #45 from fent/master

set `headerSent` on `header` event
  • Loading branch information...
commit ab658b0487372b5312911b927cef0a121cf8e7f7 2 parents 47bbb17 + afd2ccb
@3rd-Eden 3rd-Eden authored
Showing with 37 additions and 0 deletions.
  1. +1 −0  lib/response-stream.js
  2. +36 −0 test/header-test.js
View
1  lib/response-stream.js
@@ -57,6 +57,7 @@ var ResponseStream = module.exports = function (options) {
this.response._renderHeaders = function () {
if (!self._emittedHeader) {
self._emittedHeader = true;
+ self.headerSent = true;
self.emit('header');
}
return self._renderHeaders.call(self.response);
View
36 test/header-test.js
@@ -0,0 +1,36 @@
+var assert = require('assert'),
+ request = require('request'),
+ vows = require('vows'),
+ union = require('../');
+
+vows.describe('union/header').addBatch({
+ 'When using `union`': {
+ 'with a server that responds with a header': {
+ topic: function () {
+ var callback = this.callback;
+ var server = union.createServer({
+ before: [
+ function (req, res) {
+ res.on('header', function() {
+ callback(null, res);
+ });
+ res.writeHead(200, { 'content-type': 'text' });
+ res.end();
+ }
+ ]
+ });
+ server.listen(9092, function() {
+ request('http://localhost:9092/');
+ });
+ },
+ 'it should have proper `headerSent` set': function (err, res) {
+ assert.isNull(err);
+ assert.isTrue(res.headerSent);
+ },
+ 'it should have proper `_emittedHeader` set': function (err, res) {
+ assert.isNull(err);
+ assert.isTrue(res._emittedHeader);
+ }
+ }
+ }
+}).export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.