-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
Reading post data example #137
Comments
There is one feature missing before we can do this effectively, and that is detecting the end of the request. This is part of #3. Once that is implemented, it should be possible to do this:
The reason it is not possible currently is because the request does not emit an |
That will be pretty cool indeed. $http->on('request', function ($req, $res) use ($container) {
$req->on('data', function($data) use ($container, $req, $res) { Thanks |
Yeah, you can read the individual chunks. And you can figure out yourself how to detect the last chunk (check #3). If you need any help, feel free to ask on IRC ;-) |
I started prototyping an idea using React, and discovered a situation where I want to wait for the full request body pretty quickly. Is a built-in solution to this any closer? Or are there any examples of detecting request-end without the framework's help? I realize I'm necroing a long-closed thread, but it seemed more appropriate than starting a new ticket, since this is exactly what I'm curious about. |
to anybody who will get here, i made a dirty example of request data receive $app = function ($request, $response) {
$requestBody='';
$headers=$request->getHeaders();
$contentLength=(int)$headers['Content-Length'];
$receivedData=0;
$request->on('data',function($data)
use ($request, $response,&$requestBody,&$receivedData,$contentLength) {
$requestBody.=$data;
$receivedData+=strlen($data);
if ($receivedData>=$contentLength) {
parse_str($requestBody, $requestData);
print_r($requestData); //here is our data
$response->end();
}
});
} |
To anybody who will get here pulling out hair because of memory leaks on post data reading with the example code above, be sure to call not only |
Hi. Is 'end' event implemented correctly? It doesn't work for me. |
FYI the components have their on repository where development happens. In regards to POST data: reactphp/http#41 (comment) |
I just have noticed that the second chunk of POST data in event onData triggers in 1 second. If there are three or more chunks issue is still reproduced only for second chunk, for others guys all works fine. Any ideas? |
The problem was that I used cURL php library for sending request to server written on reactphp. As far as I can see, when I send long POST data cURL sets Expect: 100-continue header. I think that cURL has something like timeout. So it does not receive any response from the server and sends request again with the actual data. In order to fix this problem you should remove the header Expect from the client request: or handle it on your server. I modified zba code example with something like this:
|
@generak13 this is expected behavior as per the RFC, see also reactphp/http#47 (comment) |
Hi,
could you please add an example of how post data would be read from request?
I tried reading the request as stream, but the result was empty so I suppose it's not the correct approach.
Request:
curl --data "key=value" http://127.0.0.1:1337
Thank you
The text was updated successfully, but these errors were encountered: