-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Set etag on pmtiles serve responses #137
Conversation
main.go
Outdated
@@ -88,6 +89,7 @@ var cli struct { | |||
CacheSize int `default:"64" help:"Size of cache in Megabytes."` | |||
Bucket string `help:"Remote bucket"` | |||
PublicURL string `help:"Public base URL of tile endpoint for TileJSON e.g. https://example.com/tiles/"` | |||
TileEtag bool `help:"Generate etag for each tile instead of using archive etag"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I implemented this it also applies to metadata json and tilejson responses. Should I remove those? Or make this --resource-etag
? or just leave it as-is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in my tests on a 32-core machine enabling this reduces throughput from 40k tiles per second to 36k tiles per second.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe --unique-etags
instead, to make it clearer the effect?
@@ -294,6 +296,7 @@ func (server *Server) getTileJSON(ctx context.Context, httpHeaders map[string]st | |||
} | |||
|
|||
httpHeaders["Content-Type"] = "application/json" | |||
httpHeaders["Etag"] = generateEtag(tilejsonBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the end result is case-insensitive but the capitalization convention seems to be ETag
with a capital T, any objections to changing it to that?
Set etag on tile, metadata, and tilejson responses. By default it uses the etag from the archive but you can opt into computing an etag per-resource with
--tile-etag
flag. The default archive etag behavior minimizes runtime overhead and is guaranteed to return a new etag when tile contents changes, but also ends up changing the etag (and purging intermediate caches) when the archive changes but an individual tile is the same between old and new archive.This also implements
If-Match
andIf-None-Match
header handling by using go's built-inhttp.ServeContent
utility. As a side effect this also means thatpmtiles serve
now supports range requests within individual tiles.