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

getRawBody different after instantiate new Request twice #11958

Closed
javierfrancia opened this issue Jul 6, 2016 · 5 comments
Closed

getRawBody different after instantiate new Request twice #11958

javierfrancia opened this issue Jul 6, 2016 · 5 comments

Comments

@javierfrancia
Copy link

javierfrancia commented Jul 6, 2016

Hi,

I believe this could be related to the issue:
#10694

Class Phalcon\Http\Reques

When I am instantiating twice new Request the second time the method getRawBody() returns empty value in a PUT Request.
E.G:

$request = new Request();
$data = $request->getRawBody();
syslog(LOG_INFO,' DATA 1: '.var_export($data,true));

$request = new Request();
$data = $request->getRawBody();
syslog(LOG_INFO,' DATA 2: '.var_export($data,true));

This is happening in version:
phalcon => enabled
Author => Phalcon Team and contributors
Version => 2.0.7
Build Date => Sep 4 2015 16:08:04
Powered by Zephir => Version 0.7.1b

@sergeyklay
Copy link
Contributor

@javierfrancia Could you please check 2.0.13?

@stamster
Copy link
Contributor

stamster commented Jul 7, 2016

Why would you instantiate Request at first place? You can use the one from memory (IoC services.php -> DI). Then, what is the point of instantiating it two times in a row, during same app runtime?

HTTP is stateless protocol, i.e. every new request from a client is literally - new request.

I guess that second time you instantiate the Request object, it will be a fresh instance (that's why we use shared services in IoC container) and thus will be missing any data from HTTP client request.

@javierfrancia
Copy link
Author

Thanks for your comment @stamster. I totally agree with that. It is weird that when you do a new Request() yo are able to get the details of a request.

I am quite amateur with Phalcon but following the documentation: https://docs.phalconphp.com/en/latest/reference/request.html. In order to get the details of the request you instantiate it.

It looks like it is an intended behaviour of this Object. In my example, I am making a request to my service.

Thanks @sergeyklay I will have a look at 2.0.13 but will then ask to change phalcon version on a production environment from 2.0.7 to 2.0.13. This will need to be prioritised in the pipeline.

@stamster
Copy link
Contributor

stamster commented Jul 7, 2016

Yes, but that example is if you only use Request as a stand-alone component.
In full MVC app (or in Micro app too) you have a benefit of each component being registered in IoC container (usually services.php) during bootstrap of the application.
So you just access Request component as:
if ($this->request->getClientAddress() === '212.216.129.50') //do something

If you instantiate it again manually it will obviously work, i.e. it will re-read raw request from PHP superglobals, but on second instance it will empty buffers.

@javierfrancia
Copy link
Author

Thanks @stamster for the explanation.

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

3 participants