Chunked encoding in requests #369
Replies: 8 comments 3 replies
-
|
Hello, Hi @MitchBradley, the server does indeed not support chunk encoding for requests. But that's a valid use case and it would be nice to support it indeed. Did you try to setup an upload handler for now ? What is happening ? I guess the upload handler receives all the raw data (chunk headers plus data and separators) right ? As I understand the spec, all recipients should in theory support all encodings like gzip, chunked, etc but that being said, MCU having limitations, some could be expensive to support (like gzip). For chunk, and since this is asynchronous, data can arrive in a non deterministic way (i.e. a chunk header could arrive in 2 separate packets). But I think only some states and counters would be required to parse that, as long as all the data is sent to the upload callback after. If you have some MRE / sample that are easy to use and isolated to provide some use case or any starting point, or want to start a PR, feel free to do it / provide them. I think this is a kind of work that could be started in a branch and be worked on / completed as the time allows it. @vortigont @me-no-dev @willmmiles WDYT ? |
Beta Was this translation helpful? Give feedback.
-
|
Since chunked encoding has no Content-Length header, WebRequest.cpp line 683 causes the body to be skipped. My current approach to fixing it involves a _chunkedRequest bool that is set when Transfer-Encoding: includes "chunked", with subsequent decoding of the body and calls to handleBody. I just started working on it so I am not very far along. I think it will be easier for me to fix the problem than to create an MRE, as my current test code is deeply embedded in a large app - but at some point I will probably need a simple test case to validate a future PR. |
Beta Was this translation helpful? Give feedback.
-
|
I suppose that it could handled by a middleware, but since chunked is a core requirement of HTTP/1.1, maybe it should be in the core code. |
Beta Was this translation helpful? Give feedback.
-
|
@MitchBradley if you are ready to have a solution then that's even better! Go for it, send a PR in one of your branch so that we (team) could also add commits in case you need help. I agree that the place you saw might be a good place to switch to this decoding if chunk is used. not sure a middle ware would help because it does not have access to the request internals and especially would not be able to process the body and send data to the upload callback. I agree it would be better to have that implemented internally and correctly supported. This usage is also larger than just webdav... Any large request could benefit of that so that would be a nice addition. |
Beta Was this translation helpful? Give feedback.
-
|
I have something basically working, but before I create a PR I would like advice on a few matters of taste and style:
enum class Chunk : uint8_t {
None = 0,
Length = 1,
...
};or would you prefer a plain enum like enum {
CHUNK_NONE = 0,
CHUNK_LENGTH = 1,
...
};
|
Beta Was this translation helpful? Give feedback.
-
|
I will try with handleUpload() to see if there are any gotchas. One concern is that it seems like a bit of an API break, since the existing code handles non-chunked PUT bodies via handleBody(). Some WebDAV clients send Content-Length framed PUT bodies, while MacOS WebDAVFS chunks the body. There is no inherent reason that the server could not use both Body and Upload, but it does feel a bit strange. |
Beta Was this translation helpful? Give feedback.
-
|
Okay, so there is one head-scratcher issue with using handleUpload() - the filename parameter. For POSTs, that filename comes from the multipart form data "name" field. For PUT, the filename is inferred by decoding the URL according to the way that the filesystem is mounted. I suppose that the filename could be the verbatim URL in the PUT case. |
Beta Was this translation helpful? Give feedback.
-
|
@MitchBradley thank you for doing this effort. I see there are several design questions, so for now i would propose to work on te PR like you do in order to come up with a draft. It will be easier to iterate / refine / discuss with a first draft. Please do not forget to add a little example (you can copy/paste/adapt an existing one). Starting a list of things to discuss:
🙏👍 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have implemented a WebDAV server in our FluidNC CNC firmware. It works well with Windows and curl clients, but uploads fail with MacOS because Mac's WebDAVFS code sends PUT data with
Transfer-Encoding: Chunkedwhich ESPAsyncWebServer does not handle. Has anyone looked into supporting chunking for requests too?Beta Was this translation helpful? Give feedback.
All reactions