Skip to content

Commit b3b6b24

Browse files
http: rebase and update 8ff6b81
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
1 parent 8ff6b81 commit b3b6b24

File tree

5 files changed

+63
-83
lines changed

5 files changed

+63
-83
lines changed

doc/api/http.markdown

+8-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ Found'`.
5959

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

62-
Returns a new instance of [http.Server](#http_class_http_server). If an `options` object containing valid TLS
63-
arguments is passed, then a HTTPS server will be returned based on the
64-
options.
62+
Returns a new instance of [http.Server](#http_class_http_server).
63+
64+
Options (an optional argument) inherits from [tls.Server][], plus:
65+
66+
- `tls`: Boolean, whether or not to return an [https.Server][] based on the
67+
options. Defaults to false.
6568

6669
The `requestListener` is a function which is automatically
6770
added to the `'request'` event.
@@ -1083,6 +1086,8 @@ authentication details.
10831086
[http.Server]: #http_class_http_server
10841087
[http.request()]: #http_http_request_options_callback
10851088
[http.request()]: #http_http_request_options_callback
1089+
[https.Server]: https.html#https_class_https_server
1090+
[tls.Server]: tls.html#tls_tls_createserver_options_secureconnectionlistener
10861091
[net.Server.close()]: net.html#net_server_close_callback
10871092
[net.Server.listen(path)]: net.html#net_server_listen_path_callback
10881093
[net.Server.listen(port)]: net.html#net_server_listen_port_host_backlog_callback

lib/_http_server.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,11 @@ ServerResponse.prototype.writeHeader = function() {
213213
};
214214

215215

216-
var TLS_ARGS = ['pfx', 'key', 'passphrase', 'cert', 'ca', 'crl', 'ciphers',
217-
'handshakeTimeout', 'honorCipherOrder', 'requestCert',
218-
'rejectUnauthorized', 'NPNProtocols', 'SNICallback',
219-
'sessionIdContext', 'secureProtocol', 'secureOptions'];
220-
221216
function Server(options, requestListener) {
222-
if (util.isObject(options)) {
223-
// Only return an HTTPS server if valid TLS args are passed
224-
for (var i = 0; i < TLS_ARGS.length; i++) {
225-
if (options.hasOwnProperty(TLS_ARGS[i]))
226-
return new require('https').Server(options, requestListener);
227-
}
217+
if (options !== null && typeof options === 'object') {
218+
// Only return an HTTPS server if options.tls is true
219+
if (options.tls)
220+
return new require('https').Server(options, requestListener);
228221
} else {
229222
requestListener = options;
230223
}

test/parallel/test-http-server.js

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ server.on('listening', function() {
9696

9797
assert(http.createServer() instanceof http.Server);
9898
assert(http.createServer({foo: 1}) instanceof http.Server);
99+
assert(http.createServer({tls: false}) instanceof http.Server);
99100

100101
process.on('exit', function() {
101102
assert.equal(4, request_number);

test/parallel/test-https-from-http.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var common = require('../common');
2+
var assert = require('assert');
3+
var fs = require('fs');
4+
var http = require('http');
5+
6+
if (!common.hasCrypto) {
7+
console.log('1..0 # Skipped: missing crypto');
8+
process.exit();
9+
}
10+
11+
var https = require('https');
12+
13+
var options = {
14+
tls: true,
15+
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
16+
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
17+
};
18+
19+
var reqCount = 0;
20+
var body = 'test';
21+
22+
var server = http.createServer(options, function(req, res) {
23+
reqCount++;
24+
res.writeHead(200, {'content-type': 'text/plain'});
25+
res.end(body);
26+
});
27+
28+
assert(server instanceof https.Server);
29+
30+
server.listen(common.PORT, function() {
31+
https.get({
32+
port: common.PORT,
33+
rejectUnauthorized: false
34+
}, function(res) {
35+
var data = '';
36+
37+
res.on('data', function(chunk) {
38+
data += chunk.toString();
39+
});
40+
41+
res.on('end', function() {
42+
assert.equal(data, body);
43+
server.close();
44+
});
45+
});
46+
});
47+
48+
process.on('exit', function() {
49+
assert.equal(1, reqCount);
50+
});

test/simple/test-https-from-http.js

-69
This file was deleted.

0 commit comments

Comments
 (0)