Skip to content

Commit

Permalink
http: rebase and update 8ff6b81
Browse files Browse the repository at this point in the history
This commit does various changes to cleanup and prep the 8ff6b81 for
merging, which include updating the commit to follow new codebase
guidelines. The following are the changes:

doc/api/http.markdown:
  - document options
lib/http.js:
  - no changes
lib/_http_server.js
  - changes regarding isObject (nodejs#647) and hasOwnProperty (nodejs#635)
  - take tls option rather than guessing based on options
test/simple/test-https-from-http.js:
  - moved to parallel directory, crypto test, removed copyright banner
test/parallel/test-http-server.js:
  - adjust for tls option
  • Loading branch information
brendanashworth committed Mar 14, 2015
1 parent 8ff6b81 commit b3b6b24
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 83 deletions.
11 changes: 8 additions & 3 deletions doc/api/http.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ Found'`.

## http.createServer([options][, requestListener])

Returns a new instance of [http.Server](#http_class_http_server). If an `options` object containing valid TLS
arguments is passed, then a HTTPS server will be returned based on the
options.
Returns a new instance of [http.Server](#http_class_http_server).

Options (an optional argument) inherits from [tls.Server][], plus:

- `tls`: Boolean, whether or not to return an [https.Server][] based on the
options. Defaults to false.

The `requestListener` is a function which is automatically
added to the `'request'` event.
Expand Down Expand Up @@ -1083,6 +1086,8 @@ authentication details.
[http.Server]: #http_class_http_server
[http.request()]: #http_http_request_options_callback
[http.request()]: #http_http_request_options_callback
[https.Server]: https.html#https_class_https_server
[tls.Server]: tls.html#tls_tls_createserver_options_secureconnectionlistener
[net.Server.close()]: net.html#net_server_close_callback
[net.Server.listen(path)]: net.html#net_server_listen_path_callback
[net.Server.listen(port)]: net.html#net_server_listen_port_host_backlog_callback
Expand Down
15 changes: 4 additions & 11 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,11 @@ ServerResponse.prototype.writeHeader = function() {
};


var TLS_ARGS = ['pfx', 'key', 'passphrase', 'cert', 'ca', 'crl', 'ciphers',
'handshakeTimeout', 'honorCipherOrder', 'requestCert',
'rejectUnauthorized', 'NPNProtocols', 'SNICallback',
'sessionIdContext', 'secureProtocol', 'secureOptions'];

function Server(options, requestListener) {
if (util.isObject(options)) {
// Only return an HTTPS server if valid TLS args are passed
for (var i = 0; i < TLS_ARGS.length; i++) {
if (options.hasOwnProperty(TLS_ARGS[i]))
return new require('https').Server(options, requestListener);
}
if (options !== null && typeof options === 'object') {
// Only return an HTTPS server if options.tls is true
if (options.tls)
return new require('https').Server(options, requestListener);
} else {
requestListener = options;
}
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ server.on('listening', function() {

assert(http.createServer() instanceof http.Server);
assert(http.createServer({foo: 1}) instanceof http.Server);
assert(http.createServer({tls: false}) instanceof http.Server);

process.on('exit', function() {
assert.equal(4, request_number);
Expand Down
50 changes: 50 additions & 0 deletions test/parallel/test-https-from-http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
var http = require('http');

if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}

var https = require('https');

var options = {
tls: true,
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};

var reqCount = 0;
var body = 'test';

var server = http.createServer(options, function(req, res) {
reqCount++;
res.writeHead(200, {'content-type': 'text/plain'});
res.end(body);
});

assert(server instanceof https.Server);

server.listen(common.PORT, function() {
https.get({
port: common.PORT,
rejectUnauthorized: false
}, function(res) {
var data = '';

res.on('data', function(chunk) {
data += chunk.toString();
});

res.on('end', function() {
assert.equal(data, body);
server.close();
});
});
});

process.on('exit', function() {
assert.equal(1, reqCount);
});
69 changes: 0 additions & 69 deletions test/simple/test-https-from-http.js

This file was deleted.

0 comments on commit b3b6b24

Please sign in to comment.