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

Post limit #1504

Open
teaglin opened this issue Apr 15, 2020 · 1 comment
Open

Post limit #1504

teaglin opened this issue Apr 15, 2020 · 1 comment

Comments

@teaglin
Copy link

teaglin commented Apr 15, 2020

Hi,

I've been looking through the documentation to increase the post limit and I can't find anything. Any help would be great! Thanks!

@mbarnach
Copy link
Member

Hi @teaglin,
what you need is: ServerOptions: https://ibm-swift.github.io/Kitura-NIO/Structs/ServerOptions.html for NIO-based or https://github.com/IBM-Swift/Kitura-net/blob/master/Sources/KituraNet/ServerOptions.swift (cannot find it in the API documentation indeed).

The idea is to create a struct that handle the limits for you:

let sizeResponse: (Int, String) -> (HTTPStatusCode, String)? = { (size, client) in
  Log.warning("Rejecting request from \(client): Size \(size) too big.")
  return (.requestTooLong, "{\"error\": \"Request too big\", \"code\": 413}")
}
let serverOptions = ServerOptions(
  requestSizeLimit: 1048576,  // 1024*1024 = 1MB
  requestSizeResponseGenerator: sizeResponse)
Kitura.addHTTPServer(onPort: 8080, with: router, options: serverOptions)

The sizeResponse closure is used to customize the log and the response code, but it is not mandatory.
The requestSizeLimit is whatever limit you want.

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

No branches or pull requests

2 participants