Skip to content

Commit

Permalink
new clean pull that replaces #42 and fixes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Feb 9, 2015
1 parent de40fd0 commit 1910c59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ function EventSource(url, eventSourceInitDict) {

options.rejectUnauthorized = !(eventSourceInitDict && eventSourceInitDict.rejectUnauthorized == false);

for (var h in options.headers) {
if (options.headers[h] === undefined) {
delete options.headers[h];
}
}

req = (isSecure ? https : http).request(options, function (res) {
// Handle HTTP redirects
if (res.statusCode == 301 || res.statusCode == 307) {
Expand Down
27 changes: 27 additions & 0 deletions test/eventsource_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,33 @@ describe('HTTP Request', function () {
});
});

it('sets undefined headers by user', function (done) {
var server = createServer(function (err, server) {
if (err) return done(err);

server.on('request', function (req) {
assert.equal(req.headers['user-agent'], 'test');
assert.equal(req.headers['cookie'], 'test=test');
assert.equal(req.headers['last-event-id'], '99');
assert.equal(req.headers['X-Something'], undefined);
server.close(done);
});

var headers = {
'User-Agent': 'test',
'Cookie': 'test=test',
'Last-Event-ID': '99',
'X-Something': undefined
};

assert.doesNotThrow(
function() {
new EventSource(server.url, {headers: headers});
}
);
});
});

[301, 307].forEach(function (status) {
it('follows http ' + status + ' redirect', function (done) {
var redirectSuffix = '/foobar';
Expand Down

0 comments on commit 1910c59

Please sign in to comment.