Add "ctx.forward" for forwarding (bypassing) requests
See original GitHub issueWhat
A new ctx.forward
utility may be added to forward the currently captured request to its original destination (bypass).
Why
- See #655
Currently bypassing is done via implicit/explicit return in the resolver. This is not intuitive and deterministic action, which also makes it hard to distinguish when the user forgot to return a mocked response, and when they meant to bypass intentionally.
With the introduction of this feature, the library could reliably print a warning when you have a handler, but return no response from the resolver—it becomes safe to assume that you forgot to do that.
API
rest.get('/user', (req, res, ctx) => {
if (anything) {
return ctx.forward()
}
return res(ctx.text('mocked'))
})
Issue Analytics
- State:
- Created 2 years ago
- Reactions:25
- Comments:20 (10 by maintainers)
Top Results From Across the Web
Strata CTX Standard Telephone User Guide
Call Forward Any Call - Set for Another Station – Enables you to forward all calls for another telephone within your telephone system....
Read more >Servlet - forward() and sendRedirect() Method With Example
When we are forwarding the client request using the forward() ... to send the response to the other servlet bypassing the 'add' value....
Read more >Configuring Client Forwarding Policies - Zscaler Help
Go to Administration > Client Forwarding Policy. Click Add Rule. The Add Client Forwarding Policy window appears. In the Add Client Forwarding Policy...
Read more >Advanced Patterns — Click Documentation (5.x)
Group): def get_command(self, ctx, cmd_name): rv = click. ... Parameters (options and arguments) are forwarded to the command callbacks as you have seen....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It might not be an
onUnhandledRequest
warning, but I do get this in my console:I’d love to be able to mark paths as explicitly bypassed / passthrough. I’d suggest though, instead of calling it
ctx.forward()
, perhaps to use the same word as mirage, and call itctx.passthrough()
, since at least to me, that makes the behavior more clear. To my mind,forward
makes it seem like sending it somewhere that it wasn’t sent initially, like forwarding an email to a new recipient.Hey, @adarnon.
There is a way to bypass any request in the handler directly right now:
Both explicit and implicit
return
in the resolver that doesn’t return a mocked response composition (res
) is treated as the instruction to perform that captured request as-is. Doing so will not produce anyonUnhandledRequest
warnings, as the request was handled, just not resolved to a mocked response.What this task is about is to introduce an explicit API to state that you wish to perform the request as-is, opposed to having to rely on how the library interprets the
return
statement.