Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST request key generation. #170

Open
Legion112 opened this issue Jan 26, 2023 · 2 comments
Open

POST request key generation. #170

Legion112 opened this issue Jan 26, 2023 · 2 comments

Comments

@Legion112
Copy link
Contributor

Test which.

// Mocking only one response 
$this->addResponse( new EthereumFeeEstimateResponse('0.01', '0.9'));
$this->requestEthereum(new EthereumFeeEstimateRequest('ETH', '199', 'abc', 'address')); // same body
$this->requestEthereum(new EthereumFeeEstimateRequest('ETH', '199', 'abc', 'address')); // same body
$this->shouldMakeCallToTheNetwork(); // Next call should throw "Mock queue is empty"
$this->requestEthereum(new EthereumFeeEstimateRequest('USDT', '199', 'abc', 'address')); // different body.

Expect that the third request will trigger a network call... but instead, it uses cache.

Due to: \Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy::getCacheKey
All CacheStrategyInterface use the following line to generate cache key $request->getMethod().$request->getUri().json_encode($cacheHeaders). Which does not include request body.

I think for POST request it is fair to add body for cache key as well.

Version: kevinrob/guzzle-cache-middleware v3.5.0

@Kevinrob
Copy link
Owner

POST queries should not be cached. POST is an unsafe method and the RFC 7234 ask us to not cache it.

A cache MUST write through requests with methods that are unsafe
(Section 4.2.1 of [RFC7231]) to the origin server; i.e., a cache is
not allowed to generate a reply to such a request before having
forwarded the request and having received a corresponding response.

https://www.rfc-editor.org/rfc/rfc7234#section-4

In your example, I think that the server should accept GET method for this kind of request.

@Legion112
Copy link
Contributor Author

Should but service does not follow it 😅 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants