Node http2: statCheck() may also return false. (#20692)

* Node http2: statCheck() may also return `false`.

https://nodejs.org/dist/latest-v8.x/docs/api/http2.html#http2_http2stream_respondwithfile_path_headers_options
says:
The options.statCheck function may also be used to cancel the send operation by
returning false

Related node code:
  - https://github.com/nodejs/node/blob/master/lib/internal/http2/core.js#L1621
  - https://github.com/nodejs/node/blob/master/lib/internal/http2/core.js#L1671

* add tests for returning false from statCheck()

* change `void|false` to `void|boolean`

* fix lint error
This commit is contained in:
Jinwoo Lee 2017-10-19 10:22:12 -07:00 committed by Andy
parent 2c1dc4970e
commit e86a56d0cc
2 changed files with 3 additions and 1 deletions

View File

@ -6112,7 +6112,7 @@ declare module "http2" {
}
export interface ServerStreamFileResponseOptions {
statCheck?: (stats: fs.Stats, headers: IncomingHttpHeaders, statOptions: StatOptions) => void;
statCheck?: (stats: fs.Stats, headers: IncomingHttpHeaders, statOptions: StatOptions) => void|boolean;
getTrailers?: (trailers: IncomingHttpHeaders) => void;
offset?: number;
length?: number;

View File

@ -3288,6 +3288,7 @@ namespace http2_tests {
serverHttp2Stream.respondWithFD(0);
serverHttp2Stream.respondWithFD(0, headers);
serverHttp2Stream.respondWithFD(0, headers, options2);
serverHttp2Stream.respondWithFD(0, headers, {statCheck: () => false});
let options3: http2.ServerStreamFileResponseOptionsWithError = {
onError: (err: NodeJS.ErrnoException) => {},
statCheck: (stats: fs.Stats, headers: http2.IncomingHttpHeaders, statOptions: http2.StatOptions) => {},
@ -3298,6 +3299,7 @@ namespace http2_tests {
serverHttp2Stream.respondWithFile('');
serverHttp2Stream.respondWithFile('', headers);
serverHttp2Stream.respondWithFile('', headers, options3);
serverHttp2Stream.respondWithFile('', headers, {statCheck: () => false});
}
// Http2Server / Http2SecureServer