You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, middleware can only modify requests before they are sent to the server. There's no way to short-circuit the middleware chain and return a response immediately, which is useful for cases like deduplicating or caching responses to avoid unnecessary network requests.
Proposal
Allow middleware's onRequest hook to return a Response object. When a middleware returns a Response:
Oh this is clever! To be honest, I just have never thought of this, but I can see the usefulness of this.
I think you’ve proposed a clear usecase of why someone would want this, and this API seems to be backwards-compatible enough I think we could add in without disrupting anyone. Since onRequest() doesn’t return a response currently, this wouldn’t a breaking change.
Would happily accept a PR for this following your proposal
Description
Currently, middleware can only modify requests before they are sent to the server. There's no way to short-circuit the middleware chain and return a response immediately, which is useful for cases like deduplicating or caching responses to avoid unnecessary network requests.
Proposal
Allow middleware's
onRequest
hook to return aResponse
object. When a middleware returns a Response:onRequest
handlers are skippedonResponse
handlers are skippedExample usage:
Checklist
The text was updated successfully, but these errors were encountered: