-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: Ability to limit request size and connection count #221
Conversation
@@ -660,3 +673,23 @@ enum KituraWebSocketUpgradeError: Error { | |||
// Unknown upgrade error | |||
case unknownUpgradeError | |||
} | |||
|
|||
class Atomic<A> { |
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.
you could use NIO's Atomic which actually is atomic and doesn't require a lock. Just add NIOConcurrencyHelpers
to Package.swift
and import NIOConcurrencyHelpers
I am closing this PR as I have implemented the other approach to limit request size and connection count in #222 . |
2232cbf
to
118c5c5
Compare
@@ -80,13 +80,15 @@ class LargePayloadTests: KituraNetTest { | |||
|
|||
func handle(request: ServerRequest, response: ServerResponse) { | |||
if request.method.uppercased() == "GET" { | |||
print("hello world") |
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.
These print statements probably want to be removed?
@@ -309,15 +324,16 @@ public class HTTPServer: Server { | |||
} | |||
.childChannelInitializer { channel in | |||
let httpHandler = HTTPRequestHandler(for: self) | |||
let config: NIOHTTPServerUpgradeConfiguration = (upgraders: upgraders, completionHandler: { _ in | |||
let config: HTTPUpgradeConfiguration = (upgraders: upgraders, completionHandler: { ctx in | |||
self.ctx = ctx |
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.
Does this new property ctx
ever get read? I can't see reference to it elsewhere in this PR
@djones6 Thanks for your feedback. |
Description
This PR allows a requestSizeLimit (maximum bytes for a request, including the header size) and connectionLimit (total number of concurrent connections) to be configured when registering a server.
Example usage:
let serverConfig = HTTPServerConfiguration(requestSizeLimit: 1024, connectionLimit: 1024)
If you do not specify either of the parameters, or do not specify a
HTTPServerConfiguration
at all, then default values are used. The defaults are defined inHTTPServerConfiguration
in Kitura-NIO here: https: //github.com/RudraniW/Kitura-NIO/blob/requestSize/Sources/KituraNet/HTTP/HTTPServerConfiguration.swiftMotivation and Context
See: #206 and Kitura/Kitura#1384