oesmith / puffing-billy

A rewriting web proxy for testing interactions between your browser and external sites. Works with ruby + rspec.
MIT License
659 stars 170 forks source link

How to correctly cache requests with metadata that changes on each request #298

Closed codemang closed 3 years ago

codemang commented 4 years ago

I'm working on integrating Stripe in my React frontend/Rails backend project. I'm trying to use PuffingBilly to cache requests between the Stripe React component and the Stripe servers.

The main request I'd like to cache is the POST to https://api.stripe.com/v1/payment_intents. That request has a body field with some keys that change on each request, like guid, sid, etc.

My first thought was to use the before_handle_request option, something like this:

  c.before_handle_request = proc { |method, url, headers, body|
    if is_payment(url)
      body.gsub!(guid_value, 'MOCK_GUID')
    end
    [method, url, headers, new_body]
  }

That way, each time I run the spec, the request body would look the same. However, I'm finding that anytime I modify the body in any way, the test fails. Even this fails.

  c.before_handle_request = proc { |method, url, headers, body|
    [method, url, headers, "THIS SHOULDN'T FAIL"]
  }
ronwsmith commented 4 years ago

Can you give more information on how the test fails? What's the error? Do you see anything in your log files from puffing-billy?

Based on your setup, I wouldn't expect puffing-billy to handle the requests at all (as you said you're going from React to Stripe).

ronwsmith commented 3 years ago

Stale issue, closing. Feel free to reopen.