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

Use http.ServeContent + add ETag header #2

Merged
merged 2 commits into from
Dec 9, 2021

Conversation

SlIdE42
Copy link
Contributor

@SlIdE42 SlIdE42 commented Dec 7, 2021

  1. Use http.ServeContent instead of io.Copy

http.ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of http.ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.

https://pkg.go.dev/net/http#ServeContent

  1. Add ETag header

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag

http.ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of http.ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.
@benbjohnson benbjohnson merged commit 2b51fa0 into benbjohnson:main Dec 9, 2021
@benbjohnson
Copy link
Owner

@SlIdE42 Thanks, looks great. I made a minor change to support non-io.ReadSeekers via a56766a.

@benbjohnson
Copy link
Owner

Released as v0.2.0.

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.

2 participants