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

Please offer a method to set the rawBody #13152

Closed
woody712 opened this issue Nov 10, 2017 · 4 comments
Closed

Please offer a method to set the rawBody #13152

woody712 opened this issue Nov 10, 2017 · 4 comments
Labels
duplicate Duplicate issue. The duplicate issue is referenced in the comments

Comments

@woody712
Copy link

Hi buddy:

I use phalcon without fpm & nginx, but I use Swoole as the web service.

In my issue,
when the client sends a request (method "PUT") to server.
In ordinary way, we will get the params by file_get_contents("php://input")
phalcon source code:

cphalcon/phalcon/http/request.zep

`public function getRawBody() -> string
{
var rawBody, contents;

let rawBody = this->_rawBody;

if empty rawBody {

		let contents = file_get_contents("php://input");
		/**
		 * We need store the read raw body because it can't be read again
		 */
		let this->_rawBody = contents;
		return contents;
}
return rawBody;

}`
the content will be saved in $_rawBody and can not be modified by outer.

I hope there will be another way to set the $_rawBody,
like public function setRawBody($content) -> string

@andrew-demb
Copy link
Contributor

As a workaround, you can define your own Request (extends from Phalcon) class with rawBody in the constructor and set it to DI on init app.

As you can see, Request haven't any methods to change the state. So, I'm against to not implement this method in a request (while request is not immutable).

@Jurigag
Copy link
Contributor

Jurigag commented Nov 14, 2017

There is already PSR-7 issue, psr-7 have method withBody which allows you to change body of request.

@woody712
Copy link
Author

@andrew-demb
Actually, I did it in my project, thx.

@sergeyklay
Copy link
Contributor

Refs: #11789

@sergeyklay sergeyklay added the duplicate Duplicate issue. The duplicate issue is referenced in the comments label Dec 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Duplicate issue. The duplicate issue is referenced in the comments
Projects
None yet
Development

No branches or pull requests

4 participants