johannesboyne / gofakes3

A simple fake AWS S3 object storage (used for local test-runs against AWS S3 APIs)
MIT License
358 stars 81 forks source link

Implement conditional caching #59

Closed DerGut closed 2 years ago

DerGut commented 2 years ago

The S3 API allows conditional caching by sending a If-None-Match Header with GET or HEAD object requests. If the value provided with the Header matches the Etag of the object, a 304 Not Modified response is returned.

If-None-Match Return the object only if its entity tag (ETag) is different from the one specified; otherwise, return a 304 (not modified) error.

from the GetObject docs

This PR implements that behavior. S3 allows for more complex conditional caching as well:

Additional Considerations about Request Headers

If both of the If-Match and If-Unmodified-Since headers are present in the request as follows: If-Match condition evaluates to true, and; If-Unmodified-Since condition evaluates to false; then, S3 returns 200 OK and the data requested.

If both of the If-None-Match and If-Modified-Since headers are present in the request as follows: If-None-Match condition evaluates to false, and; If-Modified-Since condition evaluates to true; then, S3 returns 304 Not Modified response code.

Especially the If-Modified-Since Header may be of use and I could add it to this PR.

codecov-commenter commented 2 years ago

Codecov Report

Merging #59 (838d828) into master (5c8dfcf) will increase coverage by 0.14%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #59      +/-   ##
==========================================
+ Coverage   67.89%   68.04%   +0.14%     
==========================================
  Files          28       28              
  Lines        2492     2497       +5     
==========================================
+ Hits         1692     1699       +7     
+ Misses        564      563       -1     
+ Partials      236      235       -1     
Impacted Files Coverage Δ
error.go 76.13% <100.00%> (+0.55%) :arrow_up:
gofakes3.go 68.04% <100.00%> (+0.53%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5c8dfcf...838d828. Read the comment docs.

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

johannesboyne commented 2 years ago

Hey @DerGut - thanks a lot for the contribution! LGTM!