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

Commit 61b1deb

Browse files
authored
Do not include access token in cache key when fetching zip archives (#363)
1 parent f9fdcbb commit 61b1deb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

vfsutil/zip.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9+
"net/url"
910
"os"
1011
"path/filepath"
1112
"strings"
@@ -54,7 +55,7 @@ func NewZipVFS(ctx context.Context, url string, onFetchStart, onFetchFailed func
5455
MaxCacheSizeBytes: MaxCacheSizeBytes,
5556
}
5657

57-
ff, err := cachedFetch(ctx, url, store, func(ctx context.Context) (io.ReadCloser, error) {
58+
ff, err := cachedFetch(ctx, withoutAuth(url), store, func(ctx context.Context) (io.ReadCloser, error) {
5859
onFetchStart()
5960
request, err := http.NewRequest("GET", url, nil)
6061
if err != nil {
@@ -115,3 +116,15 @@ func setAuthFromNetrc(req *http.Request) {
115116
}
116117
req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", machine.Login, machine.Password))))
117118
}
119+
120+
// Create a new URL that doesn't include the user:password (the access
121+
// token) so that the same repository at a revision for a different user
122+
// results in a cache hit.
123+
func withoutAuth(urlString string) string {
124+
u, err := url.Parse(urlString)
125+
if err != nil {
126+
return urlString
127+
}
128+
u.User = nil
129+
return u.String()
130+
}

0 commit comments

Comments
 (0)