Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add createConnection option for http or https requests #120

Merged
merged 1 commit into from Jan 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/eventsource.js
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
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