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

Cache only valid responses #531

Merged
merged 4 commits into from
Sep 6, 2022

Conversation

dritter
Copy link
Contributor

@dritter dritter commented Aug 15, 2022

Hi!

Recently we discovered that some requests to fetch the metadata failed, but were cached regardless of the status code. This PR adds a guard, that only valid responses are cached.

This fixes #530

@dritter
Copy link
Contributor Author

dritter commented Aug 23, 2022

@schlessera Any chance to get this merged? This is quite urgent for us, because all our amp pages are invalid without this fix (see #530 ).

@swissspidy
Copy link
Contributor

cc @westonruter

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -132,7 +132,7 @@ static function ($curl, $header) use (&$headers) {
$curlErrno = curl_errno($curlHandle);
curl_close($curlHandle);

if ($body === false) {
if ($body === false || $status < 200 || $status >= 300) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work as expected, but note that I believe $status could be 0. In this case, $body should also be false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! I am not sure, if I understand you correctly. Is there anything to do left?

If $status can be 0, it should IMHO be treated as error. And this code does that (smaller than 200).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm saying the same thing. In the error case, $status should be 0 and it will work as expected.

@westonruter westonruter merged commit 17aeab9 into ampproject:main Sep 6, 2022
@westonruter westonruter added this to the 0.11.3 milestone Feb 7, 2023
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

Successfully merging this pull request may close these issues.

i-amphtml-version=0 is invalid
4 participants