nim-lang / RFCs

A repository for your Nim proposals.
137 stars 23 forks source link

asynchttpserver: defer socket reading or read large request body to disk to handle large file uploads efficiently #354

Open jivank opened 3 years ago

jivank commented 3 years ago

Currently asynchttpserver reads the entire body into memory which makes anything dependent on it unable to handle large file uploads.

Please see this issue for more info: https://github.com/nim-lang/Nim/issues/17331

There are two ways that this could be handled that come to mind:

  1. Defer socket reading and let the framework deal with it
  2. Parse the form with asynchttpserver and provide new fields to Request

I think option 1 is probably the better choice to leave some flexibility to the framework. Also it seems to be inline with how Go handles this: https://golang.org/pkg/net/http/#Request.ParseMultipartForm

The only pro for option 2 I can think of is that the framework won't have to do it. But as I said it is possible in some use cases just deferring the reading the body to the framework might be more flexible to build upon.

Araq commented 3 years ago

I prefer (1) too, assuming it implies less code for asynchttpserver.

dom96 commented 3 years ago

Option (1) would also match how httpclient does it.