resty icon indicating copy to clipboard operation
resty copied to clipboard

Allow OnAfterResponse ResponseMiddleware to run on all paths

Open lggomez opened this issue 4 years ago • 7 comments

As of now, custom response middlewares are only executed on the happy path of a request (that is, no error and with notParseResponse == false due to them being in the same list as the internal Resty middlewares for response handling

It is desirable that the user defined middlewares are executed on all paths and let the response handling to the user (as user defined request middlewares work now)

lggomez avatar Jul 21 '20 16:07 lggomez

Due to middlewares cannot run on all paths, I have to design a new Middleware layer base on Wrapping Transport. QAQ

zhong-wx avatar Sep 03 '20 09:09 zhong-wx

@lggomez I believe you're referring to response middlewares correct? If so what is the behavior you're trying to propose, do you mind showcasing via PR?

jeevatkm avatar Sep 04 '20 22:09 jeevatkm

Yes. The work involved is similar to #355, plus a separation of afterResponse and udAfterResponse so that OnAfterRequest middlewares behave exactly that the OnBefore ones, internal ones first and client defined after

Now that you solved the ci issue (thanks!) I was hoping to take a shot at this soon

lggomez avatar Sep 05 '20 01:09 lggomez

@lggomez You're welcome, it was a config issue with Travis build.

Resty's middleware behavior (typically it should) will halt the execution at middleware which had an error regardless of internal or user-defined middleware.

#355 is different (thanks again for submitting PR). I'm trying to understand the design & approach of "run on all paths", could you please describe?

jeevatkm avatar Sep 05 '20 22:09 jeevatkm

I think "run on all paths" meas that afterResponse middlewares will be execute whether the request and beforeRequest middlewares are done successfully or not

zhong-wx avatar Sep 06 '20 03:09 zhong-wx

It is as @zhong-wx says, I layed out the initial implementation on the linked PR

lggomez avatar Sep 08 '20 15:09 lggomez

There is a middleware redesign coming in v3, so Resty users get to choose the middleware execution and its order. Plus this issue suggestion I will consider applying this on default flow.

jeevatkm avatar Oct 01 '23 04:10 jeevatkm