Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 9a8953d

Browse files
committed
Merge nodejs/master
Merge 4d893e0 as of 2017-08-27. This is an automatically created merge. For any problems please contact @kunalspathak.
2 parents 85767d6 + 4d893e0 commit 9a8953d

26 files changed

+506
-382
lines changed

BUILDING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ Prerequisites:
170170
including the Community edition (remember to select
171171
"Common Tools for Visual C++ 2015" feature during installation).
172172
* [Visual Studio 2017](https://www.visualstudio.com/downloads/), any edition (including the Build Tools SKU).
173-
**Required Components:** "MSbuild", "VC++ 2017 v141 toolset" and one of the Windows SDKs (10 or 8.1).
173+
**Required Components:** "MSbuild", "VC++ 2017 v141 toolset" and at least one of the Windows SDKs.
174+
*Note*: For "Windows 10 SDK (10.0.15063.0)" only the "Desktop C++ x86 and x64" flavor is required.
174175
* Basic Unix tools required for some tests,
175176
[Git for Windows](http://git-scm.com/download/win) includes Git Bash
176177
and tools which can be included in the global `PATH`.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ test-all-valgrind: test-build
333333
$(PYTHON) tools/test.py --mode=debug,release --valgrind
334334

335335
CI_NATIVE_SUITES := addons addons-napi
336-
CI_JS_SUITES := async-hooks doctool inspector known_issues message parallel pseudo-tty sequential
336+
CI_JS_SUITES := abort async-hooks doctool inspector known_issues message parallel pseudo-tty sequential
337337

338338
# Build and test addons without building anything else
339339
test-ci-native: LOGLEVEL := info

doc/api/errors.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,11 @@ are most likely an indication of a bug within Node.js itself.
11411141
Used when the V8 BreakIterator API is used but the full ICU data set is not
11421142
installed.
11431143

1144+
<a id="ERR_VALUE_OUT_OF_RANGE"></a>
1145+
### ERR_VALUE_OUT_OF_RANGE
1146+
1147+
Used when a given value is out of the accepted range.
1148+
11441149
[`ERR_INVALID_ARG_TYPE`]: #ERR_INVALID_ARG_TYPE
11451150
[`subprocess.kill()`]: child_process.html#child_process_subprocess_kill_signal
11461151
[`subprocess.send()`]: child_process.html#child_process_subprocess_send_message_sendhandle_options_callback

doc/api/http2.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,6 @@ added: v8.4.0
11181118
* `headers` {[Headers Object][]}
11191119
* `options` {Object}
11201120
* `statCheck` {Function}
1121-
* `onError` {Function} Callback function invoked in the case of an
1122-
Error before send
11231121
* `getTrailers` {Function} Callback function invoked to collect trailer
11241122
headers.
11251123
* `offset` {number} The offset position at which to begin reading
@@ -1148,16 +1146,6 @@ server.on('stream', (stream) => {
11481146
function statCheck(stat, headers) {
11491147
headers['last-modified'] = stat.mtime.toUTCString();
11501148
}
1151-
1152-
function onError(err) {
1153-
if (err.code === 'ENOENT') {
1154-
stream.respond({ ':status': 404 });
1155-
} else {
1156-
stream.respond({ ':status': 500 });
1157-
}
1158-
stream.end();
1159-
}
1160-
11611149
stream.respondWithFile('/some/file',
11621150
{ 'content-type': 'text/plain' },
11631151
{ statCheck });
@@ -1190,10 +1178,6 @@ The `offset` and `length` options may be used to limit the response to a
11901178
specific range subset. This can be used, for instance, to support HTTP Range
11911179
requests.
11921180

1193-
The `options.onError` function may also be used to handle all the errors
1194-
that could happen before the delivery of the file is initiated. The
1195-
default behavior is to destroy the stream.
1196-
11971181
When set, the `options.getTrailers()` function is called immediately after
11981182
queuing the last chunk of payload data to be sent. The callback is passed a
11991183
single object (with a `null` prototype) that the listener may used to specify
@@ -1224,19 +1208,6 @@ added: v8.4.0
12241208

12251209
* Extends: {net.Server}
12261210

1227-
In `Http2Server`, there is no `'clientError'` event as there is in
1228-
HTTP1. However, there are `'socketError'`, `'sessionError'`, and
1229-
`'streamError'`, for error happened on the socket, session or stream
1230-
respectively.
1231-
1232-
#### Event: 'socketError'
1233-
<!-- YAML
1234-
added: v8.4.0
1235-
-->
1236-
1237-
The `'socketError'` event is emitted when a `'socketError'` event is emitted by
1238-
an `Http2Session` associated with the server.
1239-
12401211
#### Event: 'sessionError'
12411212
<!-- YAML
12421213
added: v8.4.0
@@ -1246,15 +1217,13 @@ The `'sessionError'` event is emitted when an `'error'` event is emitted by
12461217
an `Http2Session` object. If no listener is registered for this event, an
12471218
`'error'` event is emitted.
12481219

1249-
#### Event: 'streamError'
1220+
#### Event: 'socketError'
12501221
<!-- YAML
1251-
added: REPLACEME
1222+
added: v8.4.0
12521223
-->
12531224

1254-
* `socket` {http2.ServerHttp2Stream}
1255-
1256-
If an `ServerHttp2Stream` emits an `'error'` event, it will be forwarded here.
1257-
The stream will already be destroyed when this event is triggered.
1225+
The `'socketError'` event is emitted when a `'socketError'` event is emitted by
1226+
an `Http2Session` associated with the server.
12581227

12591228
#### Event: 'stream'
12601229
<!-- YAML

lib/_tls_common.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'use strict';
2323

2424
const tls = require('tls');
25+
const errors = require('internal/errors');
2526

2627
const SSL_OP_CIPHER_SERVER_PREFERENCE =
2728
process.binding('constants').crypto.SSL_OP_CIPHER_SERVER_PREFERENCE;
@@ -52,6 +53,14 @@ function SecureContext(secureProtocol, secureOptions, context) {
5253
if (secureOptions) this.context.setOptions(secureOptions);
5354
}
5455

56+
function validateKeyCert(value, type) {
57+
if (typeof value !== 'string' && !ArrayBuffer.isView(value))
58+
throw new errors.TypeError(
59+
'ERR_INVALID_ARG_TYPE', type,
60+
['string', 'Buffer', 'TypedArray', 'DataView']
61+
);
62+
}
63+
5564
exports.SecureContext = SecureContext;
5665

5766

@@ -71,10 +80,12 @@ exports.createSecureContext = function createSecureContext(options, context) {
7180
// cert's issuer in C++ code.
7281
if (options.ca) {
7382
if (Array.isArray(options.ca)) {
74-
for (i = 0; i < options.ca.length; i++) {
75-
c.context.addCACert(options.ca[i]);
76-
}
83+
options.ca.forEach((ca) => {
84+
validateKeyCert(ca, 'ca');
85+
c.context.addCACert(ca);
86+
});
7787
} else {
88+
validateKeyCert(options.ca, 'ca');
7889
c.context.addCACert(options.ca);
7990
}
8091
} else {
@@ -83,9 +94,12 @@ exports.createSecureContext = function createSecureContext(options, context) {
8394

8495
if (options.cert) {
8596
if (Array.isArray(options.cert)) {
86-
for (i = 0; i < options.cert.length; i++)
87-
c.context.setCert(options.cert[i]);
97+
options.cert.forEach((cert) => {
98+
validateKeyCert(cert, 'cert');
99+
c.context.setCert(cert);
100+
});
88101
} else {
102+
validateKeyCert(options.cert, 'cert');
89103
c.context.setCert(options.cert);
90104
}
91105
}
@@ -96,12 +110,12 @@ exports.createSecureContext = function createSecureContext(options, context) {
96110
// which leads to the crash later on.
97111
if (options.key) {
98112
if (Array.isArray(options.key)) {
99-
for (i = 0; i < options.key.length; i++) {
100-
const key = options.key[i];
101-
const passphrase = key.passphrase || options.passphrase;
102-
c.context.setKey(key.pem || key, passphrase);
103-
}
113+
options.key.forEach((k) => {
114+
validateKeyCert(k.pem || k, 'key');
115+
c.context.setKey(k.pem || k, k.passphrase || options.passphrase);
116+
});
104117
} else {
118+
validateKeyCert(options.key, 'key');
105119
c.context.setKey(options.key, options.passphrase);
106120
}
107121
}

lib/http2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515
createSecureServer,
1616
connect,
1717
Http2ServerRequest,
18-
Http2ServerResponse
18+
Http2ServerResponse,
1919
} = require('internal/http2/core');
2020

2121
module.exports = {
@@ -27,5 +27,5 @@ module.exports = {
2727
createSecureServer,
2828
connect,
2929
Http2ServerResponse,
30-
Http2ServerRequest
30+
Http2ServerRequest,
3131
};

lib/internal/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ E('ERR_ENCODING_INVALID_ENCODED_DATA',
117117
(enc) => `The encoded data was not valid for encoding ${enc}`);
118118
E('ERR_HTTP_HEADERS_SENT',
119119
'Cannot %s headers after they are sent to the client');
120-
E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s');
121120
E('ERR_HTTP_TRAILER_INVALID',
122121
'Trailers are invalid with this transfer encoding');
123122
E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.');
@@ -269,6 +268,7 @@ E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' +
269268
'See https://github.com/nodejs/node/wiki/Intl');
270269
E('ERR_VALID_PERFORMANCE_ENTRY_TYPE',
271270
'At least one valid performance entry type is required');
271+
E('ERR_VALUE_OUT_OF_RANGE', 'The value of "%s" must be %s. Received "%s"');
272272

273273
function invalidArgType(name, expected, actual) {
274274
assert(name, 'name is required');

lib/internal/http2/compat.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,8 @@ function onStreamEnd() {
5858
}
5959

6060
function onStreamError(error) {
61-
// this is purposefully left blank
62-
//
63-
// errors in compatibility mode are
64-
// not forwarded to the request
65-
// and response objects. However,
66-
// they are forwarded to 'clientError'
67-
// on the server by Http2Stream
61+
const request = this[kRequest];
62+
request.emit('error', error);
6863
}
6964

7065
function onRequestPause() {
@@ -87,6 +82,11 @@ function onStreamResponseDrain() {
8782
response.emit('drain');
8883
}
8984

85+
function onStreamResponseError(error) {
86+
const response = this[kResponse];
87+
response.emit('error', error);
88+
}
89+
9090
function onStreamClosedRequest() {
9191
const req = this[kRequest];
9292
req.push(null);
@@ -271,7 +271,9 @@ class Http2ServerResponse extends Stream {
271271
stream[kResponse] = this;
272272
this.writable = true;
273273
stream.on('drain', onStreamResponseDrain);
274+
stream.on('error', onStreamResponseError);
274275
stream.on('close', onStreamClosedResponse);
276+
stream.on('aborted', onAborted.bind(this));
275277
const onfinish = this[kFinish].bind(this);
276278
stream.on('streamClosed', onfinish);
277279
stream.on('finish', onfinish);

lib/internal/http2/core.js

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,13 +1506,6 @@ class Http2Stream extends Duplex {
15061506
this.once('ready', this._destroy.bind(this, err, callback));
15071507
return;
15081508
}
1509-
1510-
const server = session[kServer];
1511-
1512-
if (err && server) {
1513-
server.emit('streamError', err, this);
1514-
}
1515-
15161509
process.nextTick(() => {
15171510
debug(`[${sessionName(session[kType])}] destroying stream ${this[kID]}`);
15181511

@@ -1536,8 +1529,9 @@ class Http2Stream extends Duplex {
15361529
// All done
15371530
const rst = this[kState].rst;
15381531
const code = rst ? this[kState].rstCode : NGHTTP2_NO_ERROR;
1539-
if (!err && code !== NGHTTP2_NO_ERROR) {
1540-
err = new errors.Error('ERR_HTTP2_STREAM_ERROR', code);
1532+
if (code !== NGHTTP2_NO_ERROR) {
1533+
const err = new errors.Error('ERR_HTTP2_STREAM_ERROR', code);
1534+
process.nextTick(() => this.emit('error', err));
15411535
}
15421536
process.nextTick(emit.bind(this, 'streamClosed', code));
15431537
debug(`[${sessionName(session[kType])}] stream ${this[kID]} destroyed`);
@@ -1640,24 +1634,13 @@ function doSendFileFD(session, options, fd, headers, getTrailers, err, stat) {
16401634
abort(this);
16411635
return;
16421636
}
1643-
const onError = options.onError;
1644-
16451637
if (err) {
1646-
if (onError) {
1647-
onError(err);
1648-
} else {
1649-
this.destroy(err);
1650-
}
1638+
process.nextTick(() => this.emit('error', err));
16511639
return;
16521640
}
1653-
16541641
if (!stat.isFile()) {
16551642
err = new errors.Error('ERR_HTTP2_SEND_FILE');
1656-
if (onError) {
1657-
onError(err);
1658-
} else {
1659-
this.destroy(err);
1660-
}
1643+
process.nextTick(() => this.emit('error', err));
16611644
return;
16621645
}
16631646

@@ -1694,17 +1677,12 @@ function doSendFileFD(session, options, fd, headers, getTrailers, err, stat) {
16941677

16951678
function afterOpen(session, options, headers, getTrailers, err, fd) {
16961679
const state = this[kState];
1697-
const onError = options.onError;
16981680
if (this.destroyed || session.destroyed) {
16991681
abort(this);
17001682
return;
17011683
}
17021684
if (err) {
1703-
if (onError) {
1704-
onError(err);
1705-
} else {
1706-
this.destroy(err);
1707-
}
1685+
process.nextTick(() => this.emit('error', err));
17081686
return;
17091687
}
17101688
state.fd = fd;
@@ -1713,20 +1691,13 @@ function afterOpen(session, options, headers, getTrailers, err, fd) {
17131691
doSendFileFD.bind(this, session, options, fd, headers, getTrailers));
17141692
}
17151693

1716-
function streamOnError(err) {
1717-
// we swallow the error for parity with HTTP1
1718-
// all the errors that ends here are not critical for the project
1719-
debug('ServerHttp2Stream errored, avoiding uncaughtException', err);
1720-
}
1721-
17221694

17231695
class ServerHttp2Stream extends Http2Stream {
17241696
constructor(session, id, options, headers) {
17251697
super(session, options);
17261698
this[kInit](id);
17271699
this[kProtocol] = headers[HTTP2_HEADER_SCHEME];
17281700
this[kAuthority] = headers[HTTP2_HEADER_AUTHORITY];
1729-
this.on('error', streamOnError);
17301701
debug(`[${sessionName(session[kType])}] created serverhttp2stream`);
17311702
}
17321703

@@ -2585,8 +2556,6 @@ module.exports = {
25852556
createServer,
25862557
createSecureServer,
25872558
connect,
2588-
Http2Session,
2589-
Http2Stream,
25902559
Http2ServerRequest,
25912560
Http2ServerResponse
25922561
};

0 commit comments

Comments
 (0)