@@ -395,6 +395,7 @@ function Server(options, requestListener) {
395395  this . timeout  =  0 ; 
396396  this . keepAliveTimeout  =  5000 ; 
397397  this . maxHeadersCount  =  null ; 
398+   this . maxRequestsPerSocket  =  null ; 
398399  this . headersTimeout  =  60  *  1000 ;  // 60 seconds 
399400  this . requestTimeout  =  0 ; 
400401} 
@@ -486,6 +487,7 @@ function connectionListenerInternal(server, socket) {
486487    // need to pause TCP socket/HTTP parser, and wait until the data will be 
487488    // sent to the client. 
488489    outgoingData : 0 , 
490+     requestsCount : 0 , 
489491    keepAliveTimeoutSet : false 
490492  } ; 
491493  state . onData  =  socketOnData . bind ( undefined , 
@@ -876,6 +878,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
876878
877879  const  res  =  new  server [ kServerResponse ] ( req ) ; 
878880  res . _keepAliveTimeout  =  server . keepAliveTimeout ; 
881+   res . _maxRequestsPerSocket  =  server . maxRequestsPerSocket ; 
879882  res . _onPendingData  =  updateOutgoingData . bind ( undefined , 
880883                                               socket ,  state ) ; 
881884
@@ -904,6 +907,16 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
904907         resOnFinish . bind ( undefined , 
905908                          req ,  res ,  socket ,  state ,  server ) ) ; 
906909
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+ 
907920  if  ( req . headers . expect  !==  undefined  && 
908921      ( req . httpVersionMajor  ===  1  &&  req . httpVersionMinor  ===  1 ) )  { 
909922    if  ( RegExpPrototypeTest ( continueExpression ,  req . headers . expect ) )  { 
0 commit comments