Skip to content
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

Phalcon\Http\Request getRawBody()/getPut() clears input buffer #10694

Closed
VeryStrongFingers opened this issue Jul 21, 2015 · 1 comment
Closed

Comments

@VeryStrongFingers
Copy link

Phalcon Module: Phalcon 2.0.5 - Windows x64 for PHP 5.5.0 (vc11)

I'm unsure if this is intended behaviour or not, please let me know if it's just my brain logic that is a bit off, but basically I've found that playing around with the request service results in the clearing of the request body.

Take this really simple app

use Phalcon\DI\FactoryDefault;

$di = new FactoryDefault();

var_dump($di->get('request')->getPut());
//var_dump($di->get('request')->getRawBody()); //Uncomment soon ;)

and take this HTTP Request

PUT /example.php

Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: text/plain; charset=UTF-8
Referer: http://localhost/example.php
Content-Length: 9
Connection: keep-alive

Request body:

this=test

Output for getPut is as expected, it displays

array(1) {
  ["this"]=>
  string(4) "test"
}

Now if you were to execute getRawBody() before the getPut() (Or vice versa, it doesn't really matter)
getRawBody() returns an empty string.

So uncomment the last application line:

var_dump($di->get('request')->getRawBody());

and you'll get back

string(0) ""

after/at the end of the response.

tl;dr: You cannot use $request->getPut(); and $request->getRawBody(); on the same request object. The latter executed will return empty.
This is intended logic?

@andresgutierrez
Copy link
Sponsor Contributor

Fixed in the 2.0.x branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants