Node: respondWithFile()'s options can have onError. (#20659)

* respondWithFile()'s `options` can have onError.

See the Node document:
https://nodejs.org/dist/latest-v8.x/docs/api/http2.html#http2_http2stream_respondwithfile_path_headers_options

And also the code:
https://github.com/nodejs/node/blob/master/lib/internal/http2/core.js#L1698

* update test
This commit is contained in:
Jinwoo Lee
2017-10-18 08:54:49 -07:00
committed by Andy
parent 2be8cb24b6
commit 63605aa515
2 changed files with 13 additions and 2 deletions

View File

@@ -6118,6 +6118,10 @@ declare module "http2" {
length?: number;
}
export interface ServerStreamFileResponseOptionsWithError extends ServerStreamFileResponseOptions {
onError?: (err: NodeJS.ErrnoException) => void;
}
export interface Http2Stream extends stream.Duplex {
readonly aborted: boolean;
readonly destroyed: boolean;
@@ -6264,7 +6268,7 @@ declare module "http2" {
pushStream(headers: OutgoingHttpHeaders, options?: StreamPriorityOptions, callback?: (pushStream: ServerHttp2Stream) => void): void;
respond(headers?: OutgoingHttpHeaders, options?: ServerStreamResponseOptions): void;
respondWithFD(fd: number, headers?: OutgoingHttpHeaders, options?: ServerStreamFileResponseOptions): void;
respondWithFile(path: string, headers?: OutgoingHttpHeaders, options?: ServerStreamFileResponseOptions): void;
respondWithFile(path: string, headers?: OutgoingHttpHeaders, options?: ServerStreamFileResponseOptionsWithError): void;
}
// Http2Session

View File

@@ -3286,9 +3286,16 @@ namespace http2_tests {
serverHttp2Stream.respondWithFD(0);
serverHttp2Stream.respondWithFD(0, headers);
serverHttp2Stream.respondWithFD(0, headers, options2);
let options3: http2.ServerStreamFileResponseOptionsWithError = {
onError: (err: NodeJS.ErrnoException) => {},
statCheck: (stats: fs.Stats, headers: http2.IncomingHttpHeaders, statOptions: http2.StatOptions) => {},
getTrailers: (trailers: http2.IncomingHttpHeaders) => {},
offset: 0,
length: 0
};
serverHttp2Stream.respondWithFile('');
serverHttp2Stream.respondWithFile('', headers);
serverHttp2Stream.respondWithFile('', headers, options2);
serverHttp2Stream.respondWithFile('', headers, options3);
}
// Http2Server / Http2SecureServer