Skip to content

feat: add etag to slim binaries endpoint #5750

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

Merged
merged 3 commits into from
Jan 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! feat: add etag to slim binaries endpoint
  • Loading branch information
deansheather committed Jan 17, 2023
commit 819f42ff6af73d4d490eba93b76348c236c6cb46
19 changes: 13 additions & 6 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ func Handler(siteFS fs.FS, binFS http.FileSystem, binHashes map[string]string) h

// Set ETag header to the SHA1 hash of the file contents.
name := filePath(r.URL.Path)
if name == "" || strings.Contains(name, "/") {
if name == "" || name == "/" {
// Serve the directory listing.
http.FileServer(binFS).ServeHTTP(rw, r)
return
}
if strings.Contains(name, "/") {
// We only serve files from the root of this directory, so avoid any
// shenanigans by blocking slashes in the URL path.
http.NotFound(rw, r)
return
}
Expand Down Expand Up @@ -489,7 +496,7 @@ func ExtractOrReadBinFS(dest string, siteFS fs.FS) (http.FileSystem, map[string]
}

// Nothing we can do, serve the cache directory, thus allowing
// binaries to be places there.
// binaries to be placed there.
binFS, err := mkdest()
if err != nil {
return nil, nil, xerrors.Errorf("mkdest failed: %w", err)
Expand Down Expand Up @@ -725,17 +732,17 @@ type binHashCache struct {
binFS http.FileSystem

hashes map[string]string
mut *sync.RWMutex
sf *singleflight.Group
mut sync.RWMutex
sf singleflight.Group
sem chan struct{}
}

func newBinHashCache(binFS http.FileSystem, binHashes map[string]string) *binHashCache {
b := &binHashCache{
binFS: binFS,
hashes: make(map[string]string, len(binHashes)),
mut: &sync.RWMutex{},
sf: &singleflight.Group{},
mut: sync.RWMutex{},
sf: singleflight.Group{},
sem: make(chan struct{}, 4),
}
// Make a copy since we're gonna be mutating it.
Expand Down