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

Support http2. #494

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ node_js:
- 6
- 8
- 9

matrix:
include:
- node_js: "9"
env: HTTP2_TEST=1
- node_js: "8"
env: HTTP2_TEST=1
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
var methods = require('methods');
var Test = require('./lib/test');
var http = require('http');
var http2;
try {
http2 = require('http2'); // eslint-disable-line global-require
} catch (_) {
// eslint-disable-line no-empty
}

/**
* Test against the given `app`,
Expand All @@ -17,12 +23,20 @@ module.exports = function(app) {
var obj = {};

if (typeof app === 'function') {
app = http.createServer(app); // eslint-disable-line no-param-reassign
if (module.exports.http2) {
app = http2.createServer(app); // eslint-disable-line no-param-reassign
} else {
app = http.createServer(app); // eslint-disable-line no-param-reassign
}
}

methods.forEach(function(method) {
obj[method] = function(url) {
return new Test(app, method, url);
var test = new Test(app, method, url);
if (module.exports.http2) {
test.http2();
}
return test;
};
});

Expand All @@ -37,6 +51,11 @@ module.exports = function(app) {
*/
module.exports.Test = Test;

/**
* Expose enable http2 property
*/
module.exports.http2 = false;

/**
* Expose the agent function
*/
Expand Down
5 changes: 3 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
var request = require('superagent');
var util = require('util');
var http = require('http');
var https = require('https');
var assert = require('assert');
var tls = require('tls');
var Request = request.Request;

/**
Expand Down Expand Up @@ -58,7 +58,8 @@ Test.prototype.serverAddress = function(app, path, host) {

if (!addr) this._server = app.listen(0);
port = app.address().port;
protocol = app instanceof https.Server ? 'https' : 'http';

protocol = app instanceof tls.Server ? 'https' : 'http';
return protocol + '://' + (host || '127.0.0.1') + ':' + port + path;
};

Expand Down
Loading