@@ -395,6 +395,7 @@ function Server(options, requestListener) {
395
395
this . timeout = 0 ;
396
396
this . keepAliveTimeout = 5000 ;
397
397
this . maxHeadersCount = null ;
398
+ this . maxRequestsPerSocket = null ;
398
399
this . headersTimeout = 60 * 1000 ; // 60 seconds
399
400
this . requestTimeout = 0 ;
400
401
}
@@ -486,6 +487,7 @@ function connectionListenerInternal(server, socket) {
486
487
// need to pause TCP socket/HTTP parser, and wait until the data will be
487
488
// sent to the client.
488
489
outgoingData : 0 ,
490
+ requestsCount : 0 ,
489
491
keepAliveTimeoutSet : false
490
492
} ;
491
493
state . onData = socketOnData . bind ( undefined ,
@@ -876,6 +878,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
876
878
877
879
const res = new server [ kServerResponse ] ( req ) ;
878
880
res . _keepAliveTimeout = server . keepAliveTimeout ;
881
+ res . _maxRequestsPerSocket = server . maxRequestsPerSocket ;
879
882
res . _onPendingData = updateOutgoingData . bind ( undefined ,
880
883
socket , state ) ;
881
884
@@ -904,6 +907,16 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
904
907
resOnFinish . bind ( undefined ,
905
908
req , res , socket , state , server ) ) ;
906
909
910
+ if ( req . httpVersionMajor === 1 && req . httpVersionMinor === 1
911
+ && typeof server . maxRequestsPerSocket === 'number'
912
+ && server . maxRequestsPerSocket > ++ state . requestsCount ) {
913
+ res . shouldKeepAlive = false ;
914
+ res . writeHead ( 503 , {
915
+ 'Connection' : 'close'
916
+ } ) ;
917
+ res . end ( ) ;
918
+ }
919
+
907
920
if ( req . headers . expect !== undefined &&
908
921
( req . httpVersionMajor === 1 && req . httpVersionMinor === 1 ) ) {
909
922
if ( RegExpPrototypeTest ( continueExpression , req . headers . expect ) ) {
0 commit comments