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

!!!TASK: Remove deprecated Http objects and replace with PSR-7 implementation #1552

Merged
merged 78 commits into from
Aug 16, 2019

Conversation

albe
Copy link
Member

@albe albe commented Apr 19, 2019

This replaces the HTTP stack of Flow with PSR-7.

Many areas of Flow are affected by this, most notably and breaking:

  • All HTTP is now fully PSR-7
  • Response in MVC controllers is no longer an HTTP response and has very different methods.
  • CLI and MVC use different dispatchers now
  • ActionRequest::getParentRequest() will return null at the top instead of an HttpRequest, you can still get the HttpRequest via ActionRequest::getHttpRequest()
  • ActionRequest::fromHttpRequest(ServerRequestInterface $httpRequest) introduced
  • ActionRequest::createSubRequest() introduced
  • ActionRequest can longer be created via new
  • \Neos\Flow\Mvc\ActionRequestFactory introduced to correctly merge arguments from the HTTP request
  • Neos.Http.Factories introduced, implementing PSR-17 HTTP factories, use those to create and fake HTTP requests
  • The HTTP process was split into more components to have easier extension points in between. So you can interject between the creation of the top level ActionRequest (after which security is avaliable) and the actual dispatching to a controller

Related: #658

Example API Changes:

  • no more Mvc\Response, instead ActionRequest and ActionResponse are the API inside the MVC stack
  • to create an ActionRequest, use the ActionRequestFactory->createActionRequest($serverRequest, $arguments)
  • inside a Controller:
    • $this->response->setHeader('Content-Type', ...) -> $this->response->setContentType(...)
    • $this->response->setHeader('Location', ...) -> $this->response->setRedirectUri(...)
    • $this->response->setStatus(...) -> $this->response->setStatusCode(...)
    • $this->response->setHeader(...) -> $this->response->setComponentParameter(SetHeaderComponent::class, ...)
  • Request::create(...) -> new ServerRequest('GET', ...)
  • $httpRequest->getBaseUri() -> $httpRequest->getAttribute(ServerRequestAttributes::BASE_URI)

@kitsunet
Copy link
Member

OK, I totally missed this change and basically started the same in parallel. I will try to rebase my work on top of this, as I have a couple of changes that are not in here yet. We might want to discuss the Factories. I currently do not use them.

@albe
Copy link
Member Author

albe commented Apr 28, 2019

Thanks for the feedback! Yes, let's discuss things. Just hit me on slack sometime this week.

This is a pretty early status and I only got the first tests pass again as easily as possible, by jumping on the Request::create* stuff to avoid rewriting all those tests. This is not how it should be ofc. If you manage to rebase your work on this or merge them together, that would be awesome!

@kitsunet
Copy link
Member

kitsunet commented Apr 29, 2019

There we go, tests will not run fully, but should be a step in the right direction. One thing to discuss is default SERVER vars as they know get applied with our request. That breaks a bunch of tests at the moment and I am not 100% sure how to fix this. Potentially could be fixed in the ServerRequestFactory but \o/ not sure

In general I didn't use the factories because in the request handler we are bound to a specific implementation anyways. It's nice to have for other components though.

@kitsunet kitsunet changed the title TASK: Remove deprecated Http objects and replace with PSR-7 implementation !!!TASK: Remove deprecated Http objects and replace with PSR-7 implementation Apr 29, 2019
Copy link
Member Author

@albe albe left a comment

Choose a reason for hiding this comment

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

Some feedback

@@ -32,6 +32,9 @@ class RequestBodyParsingComponent implements ComponentInterface
public function handle(ComponentContext $componentContext)
{
$httpRequest = $componentContext->getHttpRequest();
if (!empty($httpRequest->getParsedBody())) {
Copy link
Member

Choose a reason for hiding this comment

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

I have to check how we handled this before, but Guzzle ServerRequset::fromGlobals() sets $_POST as parsedBody, so if it was a "normal" POST request the parsed body will be fine already at this point.

Copy link
Member Author

@albe albe May 12, 2019

Choose a reason for hiding this comment

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

Before we just merged $_POST into arguments on Request creation and kept the request body around until we parsed it when mapping arguments for the ActionController. Guzzle is more correct in assigning the POST as parsed Body, if it exists. It's just a PHP inbuilt request body parsing for multipart/form-data/application/x-www-form-urlencoded after all (which apparently only works for POST requests but e.g. not PUT).

Copy link
Member Author

@albe albe left a comment

Choose a reason for hiding this comment

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

A bit of feedback. Generally, this isn't as weird as I thought, but it brings up a couple of locations, where our current logic is lacking, because we end up invoking ->render() and completely ignoring the return value.

@kitsunet
Copy link
Member

Alright, more tomorrow, I am done for today...

Copy link
Member

@kitsunet kitsunet left a comment

Choose a reason for hiding this comment

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

Proxy review.

@kitsunet kitsunet merged commit e2f21c0 into neos:master Aug 16, 2019
@kitsunet kitsunet deleted the http-psr7 branch August 16, 2019 14:11
@kitsunet kitsunet restored the http-psr7 branch August 16, 2019 14:11
@kitsunet
Copy link
Member

I restored the branch just in case.... with such a big change you never know...

bwaidelich added a commit to bwaidelich/flow-development-collection that referenced this pull request Aug 23, 2019
Previously the `Dispatcher` invoked the `startAuthentication()` method
of all authenticated tokens.

That behavior was changed by accident with neos#1552 and now only the first
Entry Point was triggered.
mhsdesign added a commit to mhsdesign/flow-development-collection that referenced this pull request Jan 30, 2024
Not to be confused with the psr requests interface.

TLTR:

Since the separation of http and cli requests
the interface is completely unused. And strict types against
its only implementation, the ActionRequest make it
impossible to implement a custom request.

_Initially_ the interface was introduced with neos@2a26925 at beginning of time. At that time this was done probably to be able to type against the interface instead of the abstract `Request` class, that the Cli and Web Request both extended.

With the removal of many methods in its interface neos@8c40ff2 and with the full separation of action and cli requests neos#1552 the interface became useless.

The dispatcher and controller interface are both typed against the `ActionRequest` and so it's impossible to implement a custom request.
mhsdesign added a commit that referenced this pull request Mar 3, 2024
TLTR:

Since the separation of http and cli requests the interface is completely unused. And strict types against its only implementation, the ActionRequest make it impossible to implement a custom request.

--------

_Initially_ the interface was introduced with 2a26925 at beginning of time. At that time this was done probably to be able to type against the interface instead of the common `Request` class, that the Cli and Web Request both extended.

With the removal of many methods in its interface 8c40ff2 and with the full separation of action and cli requests #1552 the interface became useless.

The dispatcher and controller interface are both typed against the `ActionRequest` and so it's impossible to implement a custom request.
mhsdesign added a commit that referenced this pull request Mar 3, 2024
TLTR:

Since the separation of http and cli requests the interface is completely unused. And strict types against its only implementation, the ActionRequest make it impossible to implement a custom request.

--------

_Initially_ the interface was introduced with 2a26925 at beginning of time. At that time this was done probably to be able to type against the interface instead of the common `Request` class, that the Cli and Web Request both extended.

With the removal of many methods in its interface 8c40ff2 and with the full separation of action and cli requests #1552 the interface became useless.

The dispatcher and controller interface are both typed against the `ActionRequest` and so it's impossible to implement a custom request.
kitsunet pushed a commit that referenced this pull request Sep 12, 2024
TLTR:

Since the separation of http and cli requests the interface is completely unused. And strict types against its only implementation, the ActionRequest make it impossible to implement a custom request.

--------

_Initially_ the interface was introduced with 2a26925 at beginning of time. At that time this was done probably to be able to type against the interface instead of the common `Request` class, that the Cli and Web Request both extended.

With the removal of many methods in its interface 8c40ff2 and with the full separation of action and cli requests #1552 the interface became useless.

The dispatcher and controller interface are both typed against the `ActionRequest` and so it's impossible to implement a custom request.
neos-bot pushed a commit to neos/flow that referenced this pull request Sep 12, 2024
TLTR:

Since the separation of http and cli requests the interface is completely unused. And strict types against its only implementation, the ActionRequest make it impossible to implement a custom request.

--------

_Initially_ the interface was introduced with neos/flow-development-collection@39b8f80 at beginning of time. At that time this was done probably to be able to type against the interface instead of the common `Request` class, that the Cli and Web Request both extended.

With the removal of many methods in its interface neos/flow-development-collection@8ab6a29 and with the full separation of action and cli requests neos/flow-development-collection#1552 the interface became useless.

The dispatcher and controller interface are both typed against the `ActionRequest` and so it's impossible to implement a custom request.
neos-bot pushed a commit to neos/flow that referenced this pull request Oct 11, 2024
TLTR:

Since the separation of http and cli requests the interface is completely unused. And strict types against its only implementation, the ActionRequest make it impossible to implement a custom request.

--------

_Initially_ the interface was introduced with neos/flow-development-collection@39b8f80 at beginning of time. At that time this was done probably to be able to type against the interface instead of the common `Request` class, that the Cli and Web Request both extended.

With the removal of many methods in its interface neos/flow-development-collection@8ab6a29 and with the full separation of action and cli requests neos/flow-development-collection#1552 the interface became useless.

The dispatcher and controller interface are both typed against the `ActionRequest` and so it's impossible to implement a custom request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants