Uh oh!
There was an error while loading. Please reload this page.
Streaming request body parsing - #41
Conversation
nazar-pc
commented
Oct 1, 2015
I saw |
WyriHaximus
commented
Oct 1, 2015
Not yet, those are also in the works though. But this is a step in that direction. The |
clue
commented
Mar 19, 2016
The HTTP message body can potentially have any size (even single fields can be huge), do we really want to store this automatically? As an alternative, nodejs only exposes the body stream and leaves it up to the consumer to pass this stream to the correct parser (for example http://stackoverflow.com/questions/4295782/how-do-you-extract-post-data-in-node-js). |
WyriHaximus
commented
Mar 19, 2016
No I want to go nodes way where a string or stream is emitted? Those can just be gathered using the buffered sink. Not sure yet about the stream part. It would result in less overhead for small fields but more code on the implementing side. |
clue
commented
Mar 19, 2016
My personal vote here would be small, independent, composable parts instead of convenience built in. Composable parts enable convenience on a higher level, such as this draft API: $http->on('request', function (Request$request, Response$response) use ($formParser) {
$formParser->parseDeferredStream($request)->then(function ($fields) use ($response) {
$response->end('hello ' . $field['name']);
}, function ($error) use ($response) {
$response->writeHead(400);
});
});Once we look into PSR-7 support, we could probably build a convenient middleware around this concept in order to make this available to each request handler. |
WyriHaximus
commented
Mar 19, 2016
That looks good, I'm assuming that is just listening to |
clue
commented
Mar 20, 2016
This exactly 👍
Yeah, I too suppose this should be easier than auto-wiring all parsers 👍 |
WyriHaximus
commented
Mar 20, 2016
Thanks for clarifying that @clue, working on that refactor right now 👍 |
WyriHaximus
commented
Mar 20, 2016
@clue what I'm working out now would have this API approximately: $http->on('request', function (Request$request, Response$response) {
FormParserFactory::create($request)->deferredStream()->then(function ($fields) use ($response) {
$response->end('hello ' . $field['name']);
}, function ($error) use ($response) {
$response->writeHead(400);
});
});Currently decoupling all that auto-wiring code |
WyriHaximus
commented
Mar 22, 2016
The last few commits remove the right wiring between the form parsers and request parser. They also add a form parser factory. Next step is adding methods like |
WyriHaximus
commented
Aug 20, 2016
Yeah Github won't even let me merge it from the site 😝 . This PR is my top ReactPHP priority at the moment, would prefer to get reactphp/http-client#58 in A.S.A.P. so I can fully focus on this right here. I'll discus with @clue how exactly we're going to cut it up, but since most of the discussion has already taken place here we can move relatively quick |
Hello gents, if I may, some remarks about the adopted design : Input:
Suggestions : Output: Regards. |
WyriHaximus
commented
Oct 8, 2016
Been spending some time splitting this PR up into smaller ones, that resulted in the following pull requests: -----------#62: Uploaded File object that doesn't make sense on it's own but it provides something needed by #72 and #73. -----------Order of merging (all PR's will be squashed on merge keeping the history clear): #69, #62, #70, #73, #71, #72 -----------Will go over @moe123's comment carefully and see where adjustment is necessary. One of the things I've already done due to @moe123's is make all the parsers cancelable. |
@andig yes #62 and #69 are done as far as I'm concerned, unless @jsor or @clue thinks otherwise. And I like to get them in soon, I'll ping them on IRC tonight and see how they look at it. Once that is in, start working on completing the other PR's. One of the issues I came across is that the urlencoded parser (#71) is going to be interesting as I can't use build in PHP functions to do the parsing without buffering. |
andig
commented
Dec 2, 2016
Can't we assume- for the time being- that buffering for this case is ok, i.e. you either have a POST blob which doesn't need decoding or you have urlencoded data that will most likely not exceed a certain size? |
WyriHaximus
commented
Dec 2, 2016
We could do that, I've set up several milestones that allows us to release this in parts. For example first getting the foundation out in |
bweston92
commented
Mar 13, 2017
Any update? |
@bweston92 See this issue for our roadmap: #120 |
| // Extract the header from the buffer | ||
| // in case the content isn't complete | ||
| list($headers, $this->buffer) = explode("\r\n\r\n", $this->buffer, 2); | ||
| list($headers, $buffer) = explode("\r\n\r\n", $this->buffer, 2); |
There was a problem hiding this comment.
This might result in a large string operation. Better use the previous strpos and check that against the $this->maxSize before. You might also want to use substr as you already have the position then.
This PR is the follow up for #13. It started out to make multipart streaming but ended up making all bodies streaming.
The parsers emit a
postevent with the key and value of a post variable andfileon uploaded files found in the request. On the request objectgetFilesis gone due to the streaming nature of the parsers.getPostis still there but it won't have everything until the entire request has been parsed.Todo: