Skip to content

Commit

Permalink
refactor: return an HTTP 413 response for too large payloads
Browse files Browse the repository at this point in the history
Before this, the connection was closed abrutly with an HTTP 502
response.

See also: f8100f9

Related: socketio/socket.io#4293
  • Loading branch information
darrachequesne committed Feb 28, 2022
1 parent ce3fe9d commit e24b27b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/transports/polling.ts
Expand Up @@ -52,7 +52,7 @@ export class Polling extends Transport {
* @param {http.IncomingMessage}
* @api private
*/
onRequest(req) {
onRequest(req: IncomingMessage & { res: ServerResponse }) {
const res = req.res;

if ("GET" === req.method) {
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Polling extends Transport {
*
* @api private
*/
onDataRequest(req, res) {
onDataRequest(req: IncomingMessage, res: ServerResponse) {
if (this.dataReq) {
// assert: this.dataRes, '.dataReq and .dataRes should be (un)set together'
this.onError("data request overlap from client");
Expand Down Expand Up @@ -155,8 +155,8 @@ export class Polling extends Transport {
}

if (contentLength > this.maxHttpBufferSize) {
chunks = isBinary ? Buffer.concat([]) : "";
req.connection.destroy();
res.writeHead(413).end();
cleanup();
}
};

Expand Down

0 comments on commit e24b27b

Please sign in to comment.