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

BUGFIX: Fix use of $this->response->set... in controllers #3407

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions Neos.Flow/Classes/Mvc/ActionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ class ActionRequest
*/
protected $format = '';

/**
* If this request has been changed and needs to be dispatched again
* @var boolean
*/
protected $dispatched = false;

/**
* The parent request – either another sub ActionRequest a main ActionRequest or null
* @var ?ActionRequest
Expand Down Expand Up @@ -656,14 +650,6 @@ public function getFormat(): string
return $this->format;
}

/**
* Resets the dispatched status to false
*/
public function __clone()
{
$this->dispatched = false;
}

/**
* We provide our own __sleep method, where we serialize all properties *except* the parentRequest if it is
* a HTTP request -- as this one contains $_SERVER etc.
Expand All @@ -672,7 +658,7 @@ public function __clone()
*/
public function __sleep()
{
$properties = ['controllerPackageKey', 'controllerSubpackageKey', 'controllerName', 'controllerActionName', 'arguments', 'internalArguments', 'pluginArguments', 'argumentNamespace', 'format', 'dispatched'];
$properties = ['controllerPackageKey', 'controllerSubpackageKey', 'controllerName', 'controllerActionName', 'arguments', 'internalArguments', 'pluginArguments', 'argumentNamespace', 'format'];
if ($this->parentRequest instanceof ActionRequest) {
$properties[] = 'parentRequest';
}
Expand Down
9 changes: 6 additions & 3 deletions Neos.Flow/Classes/Mvc/Controller/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function processRequest(ActionRequest $request): ResponseInterface
$this->initializeView($this->view);
}

$httpResponse = $this->callActionMethod($request, $this->arguments, $response->buildHttpResponse());
$httpResponse = $this->callActionMethod($request, $this->arguments, $response);

if (!$httpResponse->hasHeader('Content-Type')) {
$httpResponse = $httpResponse->withHeader('Content-Type', $this->negotiatedMediaType);
Expand Down Expand Up @@ -512,9 +512,9 @@ protected function initializeAction()
*
* @param ActionRequest $request
* @param Arguments $arguments
* @param ResponseInterface $httpResponse The most likely empty response, previously available as $this->response
* @param ActionResponse $response The most likely empty response, previously available as $this->response
*/
protected function callActionMethod(ActionRequest $request, Arguments $arguments, ResponseInterface $httpResponse): ResponseInterface
protected function callActionMethod(ActionRequest $request, Arguments $arguments, ActionResponse $response): ResponseInterface
{
$preparedArguments = [];
foreach ($arguments as $argument) {
Expand Down Expand Up @@ -555,6 +555,9 @@ protected function callActionMethod(ActionRequest $request, Arguments $arguments
}
}

// freeze $response previously available as $this->response
$httpResponse = $response->buildHttpResponse();

if ($actionResult instanceof ResponseInterface) {
return $actionResult;
}
Expand Down
10 changes: 10 additions & 0 deletions Neos.Flow/Tests/Functional/Mvc/ActionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public function defaultTemplateIsResolvedAndUsedAccordingToConventions()
self::assertEquals('Fourth action <b>[email protected]</b>', $response->getBody()->getContents());
}

/**
* @test
*/
public function requestAndResponseAreAvailableInTheAction()
{
$response = $this->browser->request('http://localhost/test/mvc/actioncontrollertesta/fifth?argument=the-value');
self::assertEquals('Fifth action (fifth) with: "the-value"', $response->getBody()->getContents());
self::assertEquals('Hello World', $response->getHeaderLine('X-Foo'));
}

/**
* Bug #36913
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public function fourthAction($emailAddress)
$this->view->assign('emailAddress', $emailAddress);
}

/**
* Tests response and request
*/
public function fifthAction()
{
$this->response->setHttpHeader('X-Foo', 'Hello World');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this $this->response->setHttpHeader doesnt work in beta14 so id say merge?

cc @kitsunet

return sprintf('Fifth action (%s) with: "%s"', $this->request->getControllerActionName(), $this->request->getArgument('argument'));
}

/**
* @param string $putArgument
* @param string $getArgument
Expand Down
Loading