oesmith/puffing-billy

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

codemang opened this issue · 2 comments

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"]
  }
  • Am I thinking about this wrong?
  • Is there a reason the test fails when I mock the request body?
  • Is there a better way of accomplishing this?

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).

Stale issue, closing. Feel free to reopen.