Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Do not include access token in cache key when fetching zip archives #363

Merged
merged 4 commits into from
Apr 5, 2019
Merged
Changes from all commits
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
15 changes: 14 additions & 1 deletion vfsutil/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -54,7 +55,7 @@ func NewZipVFS(ctx context.Context, url string, onFetchStart, onFetchFailed func
MaxCacheSizeBytes: MaxCacheSizeBytes,
}

ff, err := cachedFetch(ctx, url, store, func(ctx context.Context) (io.ReadCloser, error) {
ff, err := cachedFetch(ctx, withoutAuth(url), store, func(ctx context.Context) (io.ReadCloser, error) {
onFetchStart()
request, err := http.NewRequest("GET", url, nil)
if err != nil {
Expand Down Expand Up @@ -115,3 +116,15 @@ func setAuthFromNetrc(req *http.Request) {
}
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", machine.Login, machine.Password))))
}

// Create a new URL that doesn't include the user:password (the access
// token) so that the same repository at a revision for a different user
// results in a cache hit.
func withoutAuth(urlString string) string {
u, err := url.Parse(urlString)
if err != nil {
return urlString
}
u.User = nil
return u.String()
}