Skip to content

Commit 4ad734b

Browse files
xv2rexxars
authored andcommitted
Add createConnection option for http or https requests (#120)
1 parent fe907fd commit 4ad734b

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/eventsource.js

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ function EventSource (url, eventSourceInitDict) {
9898
// but for now exists as a backwards-compatibility layer
9999
options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized)
100100

101+
if (eventSourceInitDict && eventSourceInitDict.createConnection !== undefined) {
102+
options.createConnection = eventSourceInitDict.createConnection
103+
}
104+
101105
// If specify http proxy, make the request to sent to the proxy server,
102106
// and include the original url in path and Host headers
103107
var useProxy = eventSourceInitDict && eventSourceInitDict.proxy

test/eventsource_test.js

+26
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var fs = require('fs')
88
var mocha = require('mocha')
99
var assert = require('assert')
1010
var u = require('url')
11+
var net = require('net')
1112

1213
var it = mocha.it
1314
var describe = mocha.describe
@@ -599,6 +600,31 @@ describe('HTTP Request', function () {
599600
})
600601
})
601602
})
603+
604+
it('checks createConnection option', function (done) {
605+
createServer(function (err, server) {
606+
if (err) return done(err)
607+
608+
var testResult = false
609+
610+
server.on('request', function () {
611+
assert.ok(testResult)
612+
server.close(done)
613+
})
614+
615+
var urlObj = u.parse(server.url)
616+
617+
new EventSource(server.url, {
618+
createConnection: function () {
619+
var connection = net.createConnection({ port: urlObj.port, host: urlObj.hostname })
620+
connection.on('connect', function () {
621+
testResult = true
622+
})
623+
return connection
624+
}
625+
})
626+
})
627+
})
602628
})
603629

604630
describe('HTTPS Support', function () {

0 commit comments

Comments
 (0)