From e86a56d0ccd8cf5d074e2cf5b0cc41acba663bf3 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Thu, 19 Oct 2017 10:22:12 -0700 Subject: [PATCH] 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 --- types/node/index.d.ts | 2 +- types/node/node-tests.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/types/node/index.d.ts b/types/node/index.d.ts index d8e8fe3358..5d0ba05b93 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -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; diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index c4cd693e03..7b36c859c7 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -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