-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit requests per connection #40082
Changes from 1 commit
0ab2852
dc611ee
8f55f74
3dd4770
719eba9
b1d70f6
729fd5a
063a83c
c5ae814
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,6 +394,7 @@ function Server(options, requestListener) { | |
this.timeout = 0; | ||
this.keepAliveTimeout = 5000; | ||
this.maxHeadersCount = null; | ||
this.maxRequestsPerSocket = null; | ||
this.headersTimeout = 60 * 1000; // 60 seconds | ||
this.requestTimeout = 0; | ||
} | ||
|
@@ -485,6 +486,7 @@ function connectionListenerInternal(server, socket) { | |
// need to pause TCP socket/HTTP parser, and wait until the data will be | ||
// sent to the client. | ||
outgoingData: 0, | ||
requestsCount: 0, | ||
keepAliveTimeoutSet: false | ||
}; | ||
state.onData = socketOnData.bind(undefined, | ||
|
@@ -875,6 +877,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { | |
|
||
const res = new server[kServerResponse](req); | ||
res._keepAliveTimeout = server.keepAliveTimeout; | ||
res._maxRequestsPerSocket = server.maxRequestsPerSocket; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this copied here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm passing |
||
res._onPendingData = updateOutgoingData.bind(undefined, | ||
socket, state); | ||
|
||
|
@@ -903,6 +906,16 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { | |
resOnFinish.bind(undefined, | ||
req, res, socket, state, server)); | ||
|
||
if (req.httpVersionMajor === 1 && req.httpVersionMinor === 1 | ||
&& typeof server.maxRequestsPerSocket === 'number' | ||
&& server.maxRequestsPerSocket > ++state.requestsCount) { | ||
res.shouldKeepAlive = false; | ||
res.writeHead(503, { | ||
'Connection': 'close' | ||
}); | ||
res.end(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is connection close correctly set here? I think shouldKeepAlive should be set to false. |
||
} | ||
|
||
if (req.headers.expect !== undefined && | ||
(req.httpVersionMajor === 1 && req.httpVersionMinor === 1)) { | ||
if (RegExpPrototypeTest(continueExpression, req.headers.expect)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure yet if state is per all sockets or there is a state per socket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for each individual socket