Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Set ETag header with correct syntax#714

Merged
zelig merged 1 commit into
swarm-network-rewritefrom
etag-fix
Jun 13, 2018
Merged

Set ETag header with correct syntax#714
zelig merged 1 commit into
swarm-network-rewritefrom
etag-fix

Conversation

@janos
Copy link
Copy Markdown
Member

@janos janos commented Jun 13, 2018

This PR sets the ETag header with the right syntax (under double quotes) in order to stdlib's http.scanETag parse it correctly when it is provided as the value of If-Range http request header.

If If-Range http header is provided in request and the http.Request has ETag header (what is the case in HandleGet and HandleGetFile functions), http.ServeContent will try to match their values in order to validate the request's Range header. If values from request If-Range and response Etag are not matched, Request header value is discarded and the server wil serve the full content with response status code 200. This is currently happening when Chrome video player makes requests. It provides the ETag value from the previous request as the value for If-Range request header. Unfortunately, that value is required to be under double quotes to stdlib's http.scanETag parse it correctly. If it is not parsed correctly, it is considered as a no match forcing the full response, instead the partial one.

This change significantly improves the performance of video playback in Chrome.

@jpeletier
Copy link
Copy Markdown
Contributor

This was my code and the change looks good to me. Good catch!

@janos
Copy link
Copy Markdown
Member Author

janos commented Jun 13, 2018

@jpeletier Thank you, no problem. I would have missed that too for sure, so I learned something new. :)

@zelig zelig merged commit e554dd6 into swarm-network-rewrite Jun 13, 2018
@frncmx frncmx deleted the etag-fix branch January 22, 2019 09:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants