Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ function EventSource (url, eventSourceInitDict) {
// but for now exists as a backwards-compatibility layer
options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized)

if (eventSourceInitDict && eventSourceInitDict.createConnection !== undefined) {
options.createConnection = eventSourceInitDict.createConnection
}

// If specify http proxy, make the request to sent to the proxy server,
// and include the original url in path and Host headers
var useProxy = eventSourceInitDict && eventSourceInitDict.proxy
Expand Down
26 changes: 26 additions & 0 deletions test/eventsource_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var fs = require('fs')
var mocha = require('mocha')
var assert = require('assert')
var u = require('url')
var net = require('net')

var it = mocha.it
var describe = mocha.describe
Expand Down Expand Up @@ -599,6 +600,31 @@ describe('HTTP Request', function () {
})
})
})

it('checks createConnection option', function (done) {
createServer(function (err, server) {
if (err) return done(err)

var testResult = false

server.on('request', function () {
assert.ok(testResult)
server.close(done)
})

var urlObj = u.parse(server.url)

new EventSource(server.url, {
createConnection: function () {
var connection = net.createConnection({ port: urlObj.port, host: urlObj.hostname })
connection.on('connect', function () {
testResult = true
})
return connection
}
})
})
})
})

describe('HTTPS Support', function () {
Expand Down