67042[TASK] Propagate "immediate" responses through the middleware stack
Commit message
Review
-
Code review CR +2 Done
- Benni Mack +2
- Christian Kuhn +1
-
Verified V +2 Done
- Benni Mack +2
- Christian Kuhn +1
- TYPO3com +1 CI
Issues 1
Files 18
- Build/Scripts/duplicateExceptionCodeCheck.sh+0 −1
- typo3/sysext/backend/Classes/Controller/LoginController.php+2 −2
- typo3/sysext/backend/Classes/Middleware/BackendUserAuthenticator.php+26 −22
- typo3/sysext/backend/Configuration/RequestMiddlewares.php+7 −0
- typo3/sysext/beuser/Classes/Controller/BackendUserController.php+2 −2
- typo3/sysext/beuser/Classes/Hook/SwitchBackUserHook.php+2 −2
- typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php4+32 −23
- typo3/sysext/core/Classes/Authentication/CommandLineUserAuthentication.php+2 −1
- typo3/sysext/core/Classes/Http/ImmediateResponseException.php1+7 −2
- typo3/sysext/core/Classes/Http/PropagateResponseException.phpnew+49 −0
- typo3/sysext/core/Classes/Middleware/ResponsePropagation.phpnew+41 −0
- typo3/sysext/core/Classes/ServiceProvider.php+6 −0
- typo3/sysext/frontend/Classes/ContentObject/Exception/ProductionExceptionHandler.php+2 −1
- typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php+12 −12
- typo3/sysext/frontend/Configuration/RequestMiddlewares.php+7 −0
- typo3/sysext/frontend/Tests/Unit/ContentObject/Exception/ProductionExceptionHandlerTest.php+16 −0
- typo3/sysext/install/Classes/ServiceProvider.php+2 −0
- typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateInformationModuleFunctionController.php+2 −2
Review log 3049
Show 1724 earlier messages
-
Benjamin Franzke uploaded patch set 1 12/06/20, 19:23
-
TYPO3com voted on patch set 1 V -1 12/06/20, 19:23 Completed build in 20s on Sun, 6 Dec, 07:23 PM Test Summary: No tests found Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7878
-
Benjamin Franzke uploaded patch set 2 12/07/20, 07:24
-
TYPO3com commented on patch set 2 12/07/20, 07:33 Completed build in 08m 54s on Mon, 7 Dec, 07:33 AM Test Summary: 231 of 32654 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7882
-
Benjamin Franzke uploaded patch set 3 12/07/20, 08:00
-
TYPO3com voted on patch set 3 V +1 12/07/20, 08:09 Completed build in 09m 27s on Mon, 7 Dec, 08:09 AM Test Summary: 32413 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7885
-
Benjamin Franzke uploaded patch set 4 12/07/20, 08:13
-
TYPO3com voted on patch set 4 V -1 12/07/20, 08:24 Completed build in 10m 58s on Mon, 7 Dec, 08:24 AM Test Summary: 32046 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7886
-
TYPO3com voted on patch set 4 V +1 12/07/20, 08:48 Completed build in 09m 57s on Mon, 7 Dec, 08:48 AM Test Summary: 32415 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7887
-
Daniel Goerz commented on patch set 4 12/07/20, 10:14
I like the idea. After looking at the approach (if I understood it correctly) a PropagateResponseException would only be catched by the new MW when it is thrown in the last RequestHandler (aka the application), right? Therefore I thought: Would it be an option to wrap each middleware in a try catch block for PropagateResponseException in the MiddlewareDispatcher (specifically in the handle() methods of the RequestHandler wrapper classes? That way we would not need a middleware to fetch the response from the exception and propagate it back plus any code called from any middleware could make use of the PropagateResponseException. -
Benjamin Franzke commented on patch set 4 12/07/20, 10:26
Reply
Upfront, given the following TYPO3 naming scheme Http\"Application" -> Middlewares -> Http\RequestHandler With this change: * Application still catches for ImmediateResponseException (and also PropagateResponseException if not catched before). * PropagateResponseExcpetion is catched as last middleware, thus it catches everything withing in requesthandler. > plus any code called from any middleware could make use of the PropagateResponseException. Yea,it's good to support that as safety net, it can still be used (although code called from middlewares SHOULD be clean code and therefore *return* responses instead of throwing them): As PropagateResponseException extends ImmediateResponseException, AbstractApplication will always catch it. So, after all, throwing "response"s is a hack around a legacy codebase. Therefore we should avoid putting this into the clean MiddlewareDispatcher. I personally feel a new middleware for this is more clean and decoupled than attaching this to the generic middleware pipeline. -
Daniel Goerz commented on patch set 4 12/07/20, 10:43
Reply
I agree that middlewares should be clean, but so should the Http\RequestHandler ;) I also understand why it might not be desirable to introduce hacky solutions into clean code like the MiddlewareDispatcher. However, with the current solution the PropagateResponseExcpetion in BackendUserAuthentication would not be propagated at all, right? So I guess one could make the argument that if we introduce such a thing as a PropagateResponseExcpetion we should ensure that it is always propagated as an response through the middleware stack. -
Daniel Goerz commented on patch set 4 12/07/20, 10:52
Reply
public function handle(ServerRequestInterface $request): ResponseInterface { try { $response = $this->middleware->process($request, $this->next); } catch (PropagateResponseException $e) { $response = $e->getResponse(); } return $response; } Wouldn't be too bad. Just saying 😊 -
Benjamin Franzke commented on patch set 4 12/07/20, 14:40
Reply
> I agree that middlewares should be clean, but so should the Http\RequestHandler ;) Hm? what's the issue with the RequestHandler? I didn't touch it :) > However, with the current solution the PropagateResponseExcpetion in BackendUserAuthentication would not be propagated at all, right? Yes, you are right, it would be handled in the AbstractApplication (with it's ImmediateResponseException) right now. So that's certainly not ideal, but shows, that the middleware should rather call code that *returns* the response, instead of throwing it. Which means that we should refactor BackendUserAuthentication to return a redirect response instead of throwing it. What I mean: Requiring middlewares to properly take care of response proagation is a good thing and prevents code smell by reyling one exceptions instead of clear code-paths. Using Immediate/PropagateResponseException is a bit like `goto` in C, it considered harmful, but sometimes needed. Therefore I wouldn't like to introduce it as the primary method of propagation, but only as safety net. I hope that makes sense. -
Benni Mack commented on patch set 4 12/07/20, 15:39
BackendUserAuthentication.php:2346since this is called in a PSR-15 middleware, a "ImmediateResponseException" is more appropriate I guess? -
Benjamin Franzke commented on patch set 4 12/07/20, 16:46
BackendUserAuthentication.php:2346ReplyYes, true, despite the fact that PropagateResponseException is a ImmediateResponseException, ImmediateResponseException would be better here as it reveals that we should refactor this to return the redirect response directly back to the middleware, instead of using hacky propagation/immediate exceptions (which I rather see as a method for legacy code, that can't directly pass back a response to the request handler). See also discussion in https://review.typo3.org/c/Packages/TYPO3.CMS/+/67042/4#message-089859671ad318222896597db81dd996ce1b7680 -
Benni Mack commented on patch set 4 12/07/20, 16:58
BackendUserAuthentication.php:2346ReplyYes. Agreed. I do have a draft to get rid of this ugly method. There are "RuntimeExceptions" thrown in this method :D -
Daniel Goerz commented on patch set 4 12/07/20, 17:05
Reply
It does. I am fine with this approach, just wanted to point out a possible alternative in MiddlewareDispatcher in case you did not think of it. I guess any solutions is not ment to stay, so it does not matter too much. For internal core code we now should keep in mind that code called from a middleware cannot expect a PropagateResponseException to do its thing. Which is fine and wont come up too often. -
Benjamin Franzke uploaded patch set 5 12/07/20, 17:37
-
Benjamin Franzke commented on patch set 5 12/07/20, 17:37
BackendUserAuthentication.php:2346ReplyOk, won't touch that area within this patch then 👍. -
TYPO3com voted on patch set 5 V +1 12/07/20, 17:48 Completed build in 10m 47s on Mon, 7 Dec, 05:48 PM Test Summary: 32413 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7931
-
Benjamin Franzke uploaded patch set 6 12/08/20, 08:29
-
Benjamin Franzke uploaded patch set 7 12/08/20, 08:32
-
TYPO3com voted on patch set 6 V +1 12/08/20, 08:40 Completed build in 10m 30s on Tue, 8 Dec, 08:40 AM Test Summary: 32413 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7949
-
TYPO3com voted on patch set 7 V +1 12/08/20, 08:44 Completed build in 11m 31s on Tue, 8 Dec, 08:44 AM Test Summary: 32411 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7950
-
Benjamin Franzke uploaded patch set 8 12/08/20, 10:16
-
TYPO3com voted on patch set 8 V -1 12/08/20, 10:20 Completed build in 04m 17s on Tue, 8 Dec, 10:20 AM Test Summary: 3 of 20937 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7955
-
Benjamin Franzke uploaded patch set 9 12/08/20, 12:40
-
TYPO3com voted on patch set 9 V -1 12/08/20, 12:51 Completed build in 10m 38s on Tue, 8 Dec, 12:51 PM Test Summary: 1 of 32647 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7959
-
TYPO3com voted on patch set 9 V +1 12/08/20, 13:06 Completed build in 09m 05s on Tue, 8 Dec, 01:06 PM Test Summary: 32413 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7962
-
Benjamin Franzke uploaded patch set 10 12/08/20, 17:51
This is a rebase on master -
TYPO3com voted on patch set 10 V +1 12/08/20, 18:03 Completed build in 11m 30s on Tue, 8 Dec, 06:03 PM Test Summary: 32413 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7971
-
Benjamin Franzke uploaded patch set 11 12/14/20, 10:23
-
TYPO3com voted on patch set 11 V -1 12/14/20, 10:34 Completed build in 10m 50s on Mon, 14 Dec, 10:34 AM Test Summary: 30789 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8149
-
TYPO3com commented on patch set 11 12/14/20, 11:55 Completed build in 09m 35s on Mon, 14 Dec, 11:55 AM Test Summary: 1 of 32658 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8153
-
TYPO3com voted on patch set 11 V +1 12/14/20, 12:08 Completed build in 09m 52s on Mon, 14 Dec, 12:08 PM Test Summary: 32417 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8154
-
Benni Mack commented on patch set 11 12/18/20, 18:43
@daniel: what's your take on the current patchset? -
Benjamin Franzke uploaded patch set 12 01/06/21, 13:52
-
TYPO3com voted on patch set 12 V -1 01/06/21, 14:02 Completed build in 09m 53s on Wed, 6 Jan, 02:02 PM Test Summary: 32561 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8683
-
TYPO3com voted on patch set 12 V +1 01/06/21, 14:44 Completed build in 1h 01m 05s on Wed, 6 Jan, 02:44 PM Test Summary: 32567 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8683
-
Christian Kuhn uploaded patch set 13 01/07/21, 18:32
-
Christian Kuhn commented on patch set 13 V +1 CR +1 01/07/21, 18:40
looks good to me, now. -
TYPO3com voted on patch set 13 V +1 01/07/21, 18:43 Completed build in 10m 41s on Thu, 7 Jan, 06:43 PM Test Summary: 32567 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8745
-
Christian Kuhn uploaded patch set 14 01/07/21, 18:44
-
Christian Kuhn voted on patch set 14 V +1 CR +1 01/07/21, 18:44
-
TYPO3com voted on patch set 14 V +1 01/07/21, 18:55 Completed build in 10m 53s on Thu, 7 Jan, 06:55 PM Test Summary: 32567 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8746
-
Benni Mack voted on patch set 14 V +2 CR +2 01/07/21, 19:13
-
Benni Mack merged patch set 15 01/07/21, 19:13
-
Benjamin Franzke commented on patch set 15 01/07/21, 20:13
ImmediateResponseException.php:29UnresolvedNote, at best Controllers actually return a response, if possible. So this is more thought for code that can't return a response (right now). But not much of a problem, just wanted to mention. Thanks for adding more explanations.