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

feat(pgs): forward etag and last-modified headers from imgproxy #179

Closed
wants to merge 1 commit into from

Conversation

mac-chaffee
Copy link
Contributor

@mac-chaffee mac-chaffee commented Dec 21, 2024

This PR in addition to #178 complete the implementation of conditional requests (#177).

  • Enabled last-modified headers from imgproxy: https://docs.imgproxy.net/configuration/options#IMGPROXY_USE_LAST_MODIFIED
  • Refactored the content-type guessing and the routing logic for requests between minio and imgproxy into the ServeObject function
  • ServeObject now returns an ObjectInfo struct so that we can inspect last-modified and etag headers coming from Minio/imgproxy

The result is that requests for images that flow through imgproxy will have the same etag and last-modified headers as files that we pull directly from minio. Example:

$ curl -iH "Host: picouser-test.pgs.dev.pico.sh" localhost:3000/avatar.jpg
HTTP/1.1 200 OK
Cache-Control: max-age=600
Cache-Status: Souin; fwd=uri-miss; stored; key=GET-http-picouser-test.pgs.dev.pico.sh-/avatar.jpg
Content-Length: 273114
Content-Type: image/jpeg
Etag: 915e552fd3a15fc0d5a8c5f2213efa32-1
Last-Modified: Sat, 21 Dec 2024 16:48:15 GMT
Surrogate-Key: picouser-test
Date: Sat, 21 Dec 2024 22:20:23 GMT

Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.


$ curl -iH "Host: picouser-test.pgs.dev.pico.sh" localhost:3000/avatar.jpg/ext:webp
HTTP/1.1 200 OK
Cache-Control: max-age=600
Cache-Status: Souin; fwd=uri-miss; stored; key=GET-http-picouser-test.pgs.dev.pico.sh-/avatar.jpg/ext:webp
Content-Length: 345164
Content-Type: image/webp
Etag: WHCbR8OqxLWx0vkUGegAbFZbcRkKZkkRFujaD2ewsS4/RIjkxNWU1NTJmZDNhMTVmYzBkNWE4YzVmMjIxM2VmYTMyLTEi
Last-Modified: Sat, 21 Dec 2024 21:48:14 GMT
Surrogate-Key: picouser-test
Date: Sat, 21 Dec 2024 22:20:26 GMT

Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.

(yes the etags in this example are missing quotes and the date is in the wrong timezone, two bugs which are fixed in #178)

Copy link
Member

@neurosnap neurosnap left a comment

Choose a reason for hiding this comment

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

nice!

@neurosnap
Copy link
Member

Resolved the conflicts and merged, thanks!

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.

None yet

2 participants