mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
fix: add a check if the res is destroyed before sending response
In the case of using `curl` or a similar tool on the command line, or if the client decides to end the request for a streamed file early without the check we would end up causing a server crash. Now, we will just not send the response as the client has already decided how to move on. fix: #10105
This commit is contained in:
@@ -4,6 +4,7 @@ import { isFunction } from '../utils/shared.utils';
|
||||
import { StreamableFileOptions } from './streamable-options.interface';
|
||||
|
||||
export interface StreamableHandlerResponse {
|
||||
destroyed: boolean;
|
||||
statusCode: number;
|
||||
send: (msg: string) => void;
|
||||
}
|
||||
@@ -15,8 +16,10 @@ export class StreamableFile {
|
||||
err: Error,
|
||||
response: StreamableHandlerResponse,
|
||||
) => void = (err: Error, res) => {
|
||||
res.statusCode = 400;
|
||||
res.send(err.message);
|
||||
if (!res.destroyed) {
|
||||
res.statusCode = 400;
|
||||
res.send(err.message);
|
||||
}
|
||||
};
|
||||
|
||||
constructor(buffer: Uint8Array, options?: StreamableFileOptions);
|
||||
|
||||
Reference in New Issue
Block a user