Closed shirshak55 closed 7 months ago
Ah, I'm not totally sure, but I think you're saying the issue is that although your cached content gets returned correctly, Mockttp is sending a request upstream anyway (and just not using the result). Is that right?
That's easy to fix - you just need to return a response
field in beforeRequest
(which runs before the request is sent upstream) if you have a cached result available. The problem is that beforeResponse is always run after the upstream request has already been sent & completed, so no matter what you do it can't skip anything.
The response option docs are here: https://httptoolkit.github.io/mockttp/interfaces/requestHandlers.CallbackRequestResult.html#response. There's some examples in the tests starting here: https://github.com/httptoolkit/mockttp/blob/64091fc9b1230064be96a2294d2d7992608ecdc0/test/integration/proxying/http-proxying.spec.ts#L565
thanks
Hi,
I want to cache response in response object and return the cached request if it already exist in the key. My initial solution is
The problem is whenever mockttp is making external request, even tho i am not using it. I see there is thenReply, but I want to do it dynamically, so it works for any links.
Thanks.