Skip to content
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

Merged
merged 18 commits into from
Oct 8, 2019

Conversation

RudraniW
Copy link
Contributor

@RudraniW RudraniW commented Aug 20, 2019

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 aHTTPServerConfiguration at all, then default values are used. The defaults are defined in HTTPServerConfiguration in Kitura-NIO here: https: //github.com/RudraniW/Kitura-NIO/blob/requestSize/Sources/KituraNet/HTTP/HTTPServerConfiguration.swift

Motivation and Context

See: #206 and Kitura/Kitura#1384

@RudraniW RudraniW changed the title [WIP] feat: Ability to limit request size and connection count #206 [WIP] feat: Ability to limit request size and connection count Aug 20, 2019
@@ -660,3 +673,23 @@ enum KituraWebSocketUpgradeError: Error {
// Unknown upgrade error
case unknownUpgradeError
}

class Atomic<A> {
Copy link

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

@RudraniW
Copy link
Contributor Author

I am closing this PR as I have implemented the other approach to limit request size and connection count in #222 .

djones6 added a commit to Kitura/Kitura that referenced this pull request Sep 5, 2019
Sources/KituraNet/HTTP/HTTPServerConfiguration.swift Outdated Show resolved Hide resolved
Sources/KituraNet/HTTP/HTTPServer.swift Outdated Show resolved Hide resolved
Sources/KituraNet/HTTP/HTTPServer.swift Outdated Show resolved Hide resolved
@@ -80,13 +80,15 @@ class LargePayloadTests: KituraNetTest {

func handle(request: ServerRequest, response: ServerResponse) {
if request.method.uppercased() == "GET" {
print("hello world")
Copy link
Contributor

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
Copy link
Contributor

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

@RudraniW
Copy link
Contributor Author

@djones6 Thanks for your feedback.
I have made the changes you asked.

djones6 added a commit to Kitura/Kitura that referenced this pull request Oct 7, 2019
@djones6 djones6 changed the title [WIP] feat: Ability to limit request size and connection count feat: Ability to limit request size and connection count Oct 7, 2019
@djones6 djones6 merged commit 29b0dde into Kitura:master Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants