Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
llow the request body to be processed outside the asynchttpserver lib…
…rary. Allow the request body to be processed outside the asynchttpserver library to break big files into chunks of data. This change does not break anything. Example: import asyncnet, asynchttpserver, asyncdispatch proc test_page(): string = return """ <!Doctype html> <html lang="en"> <head> <meta charset="utf-8"/> </head> <body> <form action="/test" method="post"> Test: <input type="text" name="test" value="post test"><br/> <input type="submit"> </form> </body> </html> """ const chunkSize = 1024 var server = newAsyncHttpServer(maxBody=102400, handleBody=false) proc cb(req: Request) {.async.} = if req.reqMethod == HttpPost: var body = "" var remainder = req.content_length while remainder > 0: let data = await req.client.recv(if remainder < chunkSize: remainder else: chunkSize) if data.len == 0: break body.add(data) remainder -= data.len if body.len != req.contentLength: await req.respond(Http400, "Bad Request. Content-Length does not match actual.") else: await req.respond(Http200, body) # req.client.close() else: await req.respond(Http200, test_page()) waitFor server.serve(Port(8080), cb)
- Loading branch information