dracony on 3.8
dracony on master
social provider VK api fix ver… VK, users.get backwards compati… Merge pull request #11 from kip… (compare)
dracony on 3.3.1
dracony on 3.2.5
Hi All. What is a proper way to work with Response? According to what I see in code it's not what promised in docs. For example, this will not work:
$response->headers->set('Content-Type', 'text/csv'); // ->headers are protected property // ->set() there is no such method
If you have created response with
$response = $responses->string('hello world');
You also cannot set headers.
Currently I'm accumulating headers separately and building response object right at the end of processor action logic, just before return. But that's feels lame. Am I missing something?
A-ha. This is the part I've missed, thanks.
And what about body? Is it proper way?
// inside Processor action method $this->response = $this->responses()->string(''); //... $this->response->body()->write($someString);
What would be proper way and moment to create response within React like environment? Should it be within
__constructor() or inside
process() where I already catch and save Request for further processing. Or, maybe, there is a better way to access current Request object inside action method?
Why do you need to write() after building the string response? If its to stream data incrementally there are better reponse types in the Responses class
Because I need response to attach headers first. And, at the last moment, when everything else is in place(within Response object) I'm adding last piece - body. In my flow, headers and body are set separately in different places.
I think the best would be to create the Reaponse as late as possible just before returning vs mutating it
This is what I do now - collect headers in array and create Response just before Action return. But it feels slightly wrong - instead of single object responsible for response I have few.
But its just preference. There is nothing special about the response class itself really. I would definitely create it in process() then in constructor. Constructor to me seems to be just for wiring things and technically a single processor can serve multiple requests in sequential calls to process()
Good point, actually. Especially according to my context, where I'm trying to run application inside RoadRunner(React-like environment). So it's not just preference.