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

Commit

Permalink
Merge nodejs/master
Browse files Browse the repository at this point in the history
Merge cd1b55a as of 2017-09-21.
This is an automatically created merge. For any problems please
contact @kunalspathak.
  • Loading branch information
chakrabot committed Sep 29, 2017
2 parents aaa4557 + cd1b55a commit 5645545
Show file tree
Hide file tree
Showing 21 changed files with 395 additions and 182 deletions.
2 changes: 1 addition & 1 deletion doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
[Crypto Constants]: #crypto_crypto_constants_1
[HTML5's `keygen` element]: http://www.w3.org/TR/html5/forms.html#the-keygen-element
[NIST SP 800-131A]: http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf
[NIST SP 800-132]: http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf
[NIST SP 800-132]: http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf
[Nonce-Disrespecting Adversaries]: https://github.com/nonce-disrespect/nonce-disrespect
[OpenSSL's SPKAC implementation]: https://www.openssl.org/docs/man1.0.2/apps/spkac.html
[RFC 2412]: https://www.rfc-editor.org/rfc/rfc2412.txt
Expand Down
3 changes: 1 addition & 2 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ instead.

Type: End-of-Life

[`Domain.dispose()`][] is removed. Recover from failed I/O actions
`Domain.dispose()` is removed. Recover from failed I/O actions
explicitly via error event handlers set on the domain instead.

<a id="DEP0013"></a>
Expand Down Expand Up @@ -688,7 +688,6 @@ difference is that `querystring.parse()` does url encoding:
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
[`Buffer.isBuffer()`]: buffer.html#buffer_class_method_buffer_isbuffer_obj
[`Domain.dispose()`]: domain.html#domain_domain_dispose
[`EventEmitter.listenerCount(emitter, eventName)`]: events.html#events_eventemitter_listenercount_emitter_eventname
[`Server.connections`]: net.html#net_server_connections
[`Server.getConnections()`]: net.html#net_server_getconnections_callback
Expand Down
15 changes: 8 additions & 7 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ in order to use the `'http2'` module.

The Core API provides a low-level interface designed specifically around
support for HTTP/2 protocol features. It is specifically *not* designed for
compatibility with the existing [HTTP/1][] module API. However, the [Compatibility API][] is.
compatibility with the existing [HTTP/1][] module API. However,
the [Compatibility API][] is.

The following illustrates a simple, plain-text HTTP/2 server using the
Core API:
Expand Down Expand Up @@ -1305,7 +1306,7 @@ added: v8.4.0
* `response` {http2.Http2ServerResponse}

Emitted each time there is a request. Note that there may be multiple requests
per session. See the [Compatibility API](compatiblity-api).
per session. See the [Compatibility API][].

#### Event: 'timeout'
<!-- YAML
Expand Down Expand Up @@ -1413,7 +1414,7 @@ added: v8.4.0
* `response` {http2.Http2ServerResponse}

Emitted each time there is a request. Note that there may be multiple requests
per session. See the [Compatibility API](compatiblity-api).
per session. See the [Compatibility API][].

#### Event: 'timeout'
<!-- YAML
Expand Down Expand Up @@ -1915,8 +1916,8 @@ req.end('Jane');

The Compatibility API has the goal of providing a similar developer experience
of HTTP/1 when using HTTP/2, making it possible to develop applications
that supports both [HTTP/1](HTTP/1) and HTTP/2. This API targets only the
**public API** of the [HTTP/1](HTTP/1), however many modules uses internal
that supports both [HTTP/1][] and HTTP/2. This API targets only the
**public API** of the [HTTP/1][], however many modules uses internal
methods or state, and those _are not supported_ as it is a completely
different implementation.

Expand Down Expand Up @@ -1976,7 +1977,7 @@ function onRequest(req, res) {
}
```

The `'request'` event works identically on both [HTTPS](https) and
The `'request'` event works identically on both [HTTPS][] and
HTTP/2.

### Class: http2.Http2ServerRequest
Expand Down Expand Up @@ -2605,7 +2606,7 @@ added: v8.4.0
Sends a response header to the request. The status code is a 3-digit HTTP
status code, like `404`. The last argument, `headers`, are the response headers.

For compatibility with [HTTP/1](), a human-readable `statusMessage` may be
For compatibility with [HTTP/1][], a human-readable `statusMessage` may be
passed as the second argument. However, because the `statusMessage` has no
meaning within HTTP/2, the argument will have no effect and a process warning
will be emitted.
Expand Down
10 changes: 6 additions & 4 deletions doc/api/os.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ The `os.release()` method returns a string identifying the operating system
release.

*Note*: On POSIX systems, the operating system release is determined by
calling uname(3). On Windows, `GetVersionExW()` is used. Please see
calling [uname(3)][]. On Windows, `GetVersionExW()` is used. Please see
https://en.wikipedia.org/wiki/Uname#Examples for more information.

## os.tmpdir()
Expand Down Expand Up @@ -374,11 +374,12 @@ added: v0.3.3
* Returns: {string}

The `os.type()` method returns a string identifying the operating system name
as returned by uname(3). For example `'Linux'` on Linux, `'Darwin'` on macOS and
`'Windows_NT'` on Windows.
as returned by [uname(3)][]. For example `'Linux'` on Linux, `'Darwin'` on macOS
and `'Windows_NT'` on Windows.

Please see https://en.wikipedia.org/wiki/Uname#Examples for additional
information about the output of running uname(3) on various operating systems.
information about the output of running [uname(3)][] on various operating
systems.

## os.uptime()
<!-- YAML
Expand Down Expand Up @@ -1223,3 +1224,4 @@ information.
[`process.arch`]: process.html#process_process_arch
[`process.platform`]: process.html#process_process_platform
[OS Constants]: #os_os_constants
[uname(3)]: https://linux.die.net/man/3/uname
60 changes: 34 additions & 26 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2090,44 +2090,38 @@ ReadStream.prototype._read = function(n) {
}
};


ReadStream.prototype._destroy = function(err, cb) {
this.close(function(err2) {
cb(err || err2);
});
};


ReadStream.prototype.close = function(cb) {
if (cb)
this.once('close', cb);

if (this.closed || typeof this.fd !== 'number') {
if (typeof this.fd !== 'number') {
this.once('open', closeOnOpen);
this.once('open', closeFsStream.bind(null, this, cb, err));
return;
}
return process.nextTick(() => this.emit('close'));

return process.nextTick(() => {
cb(err);
this.emit('close');
});
}

this.closed = true;

fs.close(this.fd, (er) => {
if (er)
this.emit('error', er);
else
this.emit('close');
});

closeFsStream(this, cb);
this.fd = null;
};

// needed because as it will be called with arguments
// that does not match this.close() signature
function closeOnOpen(fd) {
this.close();
function closeFsStream(stream, cb, err) {
fs.close(stream.fd, (er) => {
er = er || err;
cb(er);
if (!er)
stream.emit('close');
});
}

ReadStream.prototype.close = function(cb) {
this.destroy(null, cb);
};

fs.createWriteStream = function(path, options) {
return new WriteStream(path, options);
};
Expand Down Expand Up @@ -2179,7 +2173,7 @@ function WriteStream(path, options) {
// dispose on finish.
this.once('finish', function() {
if (this.autoClose) {
this.close();
this.destroy();
}
});
}
Expand Down Expand Up @@ -2276,7 +2270,21 @@ WriteStream.prototype._writev = function(data, cb) {


WriteStream.prototype._destroy = ReadStream.prototype._destroy;
WriteStream.prototype.close = ReadStream.prototype.close;
WriteStream.prototype.close = function(cb) {
if (this._writableState.ending) {
this.on('close', cb);
return;
}

if (this._writableState.ended) {
process.nextTick(cb);
return;
}

// we use end() instead of destroy() because of
// https://github.com/nodejs/node/issues/2006
this.end(cb);
};

// There is no shutdown() for files.
WriteStream.prototype.destroySoon = WriteStream.prototype.end;
Expand Down
38 changes: 19 additions & 19 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function onStreamError(error) {
// errors in compatibility mode are
// not forwarded to the request
// and response objects. However,
// they are forwarded to 'clientError'
// they are forwarded to 'streamError'
// on the server by Http2Stream
}

Expand Down Expand Up @@ -248,9 +248,9 @@ class Http2ServerRequest extends Readable {
}

setTimeout(msecs, callback) {
const stream = this[kStream];
if (stream === undefined) return;
stream.setTimeout(msecs, callback);
if (this[kState].closed)
return;
this[kStream].setTimeout(msecs, callback);
}

[kFinish](code) {
Expand Down Expand Up @@ -445,7 +445,7 @@ class Http2ServerResponse extends Stream {

if (stream === undefined) {
const err = new errors.Error('ERR_HTTP2_STREAM_CLOSED');
if (cb)
if (typeof cb === 'function')
process.nextTick(cb, err);
else
throw err;
Expand All @@ -461,12 +461,11 @@ class Http2ServerResponse extends Stream {
if (typeof chunk === 'function') {
cb = chunk;
chunk = null;
encoding = 'utf8';
} else if (typeof encoding === 'function') {
cb = encoding;
encoding = 'utf8';
}
if (stream === undefined || stream.finished === true) {
if (this.finished === true) {
return false;
}
if (chunk !== null && chunk !== undefined) {
Expand All @@ -482,21 +481,21 @@ class Http2ServerResponse extends Stream {
}

destroy(err) {
const stream = this[kStream];
if (stream === undefined) {
// nothing to do, already closed
if (this[kState].closed)
return;
}
stream.destroy(err);
this[kStream].destroy(err);
}

setTimeout(msecs, callback) {
const stream = this[kStream];
if (stream === undefined) return;
if (this[kState].closed)
return;
stream.setTimeout(msecs, callback);
}

createPushResponse(headers, callback) {
if (typeof callback !== 'function')
throw new errors.TypeError('ERR_INVALID_CALLBACK');
const stream = this[kStream];
if (stream === undefined) {
process.nextTick(callback, new errors.Error('ERR_HTTP2_STREAM_CLOSED'));
Expand All @@ -513,12 +512,9 @@ class Http2ServerResponse extends Stream {
if (stream !== undefined &&
stream.destroyed === false &&
stream.headersSent === false) {
options = options || Object.create(null);
const state = this[kState];
const headers = this[kHeaders];
headers[HTTP2_HEADER_STATUS] = state.statusCode;
if (stream.finished === true)
options.endStream = true;
headers[HTTP2_HEADER_STATUS] = this[kState].statusCode;
options = options || Object.create(null);
options.getTrailers = (trailers) => {
Object.assign(trailers, this[kTrailers]);
};
Expand All @@ -542,7 +538,11 @@ class Http2ServerResponse extends Stream {
// TODO doesn't support callbacks
writeContinue() {
const stream = this[kStream];
if (stream === undefined) return false;
if (stream === undefined ||
stream.headersSent === true ||
stream.destroyed === true) {
return false;
}
this[kStream].additionalHeaders({
[HTTP2_HEADER_STATUS]: HTTP_STATUS_CONTINUE
});
Expand Down
Loading

0 comments on commit 5645545

Please sign in to comment.