Skip to content

Commit

Permalink
feat(web-server): allow overriding of default http module
Browse files Browse the repository at this point in the history
allow setting an external module for use by KarmaServer

Closes #2424
  • Loading branch information
itslenny committed Nov 10, 2016
1 parent 39d378d commit 1e7514d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,17 @@ Determines the use of the Node `http` or `https` class.
Note: Using `'https:'` requires you to specify `httpsServerOptions`.


## httpModule
**Type:** String

**Default:** `undefined`

**Description:** Module used for Karma webserver.

Uses the provided module instead of node's built in `http` or `https` module. The module loaded here must exactly match the interface of node's http module. This can be useful for loading in a module like `node-http2` to allow for http2 support.

Note: if you're using this to enable `http2` you must also set the `protocol` to `https:` and specify certificates as http2 can only run of https.

## proxies
**Type:** Object

Expand Down
5 changes: 5 additions & 0 deletions lib/web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ var createWebServer = function (injector, emitter, fileList) {
serverClass = https
serverArguments.unshift(config.httpsServerOptions || {})
}

if (config.httpModule) {
serverClass = config.httpModule
}

var server = serverClass.createServer.apply(null, serverArguments)

server.on('upgrade', function (req, socket, head) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@
"grunt-eslint": "^18.0.0",
"grunt-mocha-test": "^0.12.7",
"grunt-npm": "0.0.2",
"http2": "^3.3.6",
"jasmine-core": "^2.3.4",
"json3": "^3.3.2",
"karma-browserify": "^5.0.1",
Expand Down
31 changes: 31 additions & 0 deletions test/unit/web-server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,35 @@ describe('web-server', () => {
.expect(200, 'CLIENT HTML')
})
})

describe('http2', () => {
var http2 = require('http2')

beforeEach(() => {
var credentials = {
key: fs.readFileSync(path.join(__dirname, '/certificates/server.key')),
cert: fs.readFileSync(path.join(__dirname, '/certificates/server.crt'))
}

customFileHandlers = []
emitter = new EventEmitter()

var injector = new di.Injector([{
config: ['value', {basePath: '/base/path', urlRoot: '/', httpModule: http2, protocol: 'https:', httpsServerOptions: credentials}],
customFileHandlers: ['value', customFileHandlers],
emitter: ['value', emitter],
fileList: ['value', {files: {served: [], included: []}}],
capturedBrowsers: ['value', null],
reporter: ['value', null],
executor: ['value', null],
proxies: ['value', null]
}])

server = injector.invoke(m.createWebServer)
})

it('should be an instance of httpModule provided in config', () => {
expect(server instanceof http2.Server).to.equal(true)
})
})
})

0 comments on commit 1e7514d

Please sign in to comment.