Skip to content

Commit c4f62e2

Browse files
committed
Normalize url string before using cache
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 6642b4d commit c4f62e2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/hostagent/proxy/proxy.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"regexp"
1313
"strconv"
14+
"strings"
1415
"time"
1516

1617
"github.com/lima-vm/lima/pkg/downloader"
@@ -92,7 +93,17 @@ func listenAndServe(opts ServerOptions) (*http.Server, error) {
9293
proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*$"))).
9394
HandleConnect(goproxy.AlwaysMitm)
9495
proxy.OnRequest().DoFunc(func(req *http.Request, _ *goproxy.ProxyCtx) (*http.Request, *http.Response) {
95-
url := req.URL.String()
96+
u := req.URL
97+
if strings.Contains(u.Host, ":") {
98+
host, port, err := net.SplitHostPort(u.Host)
99+
if err != nil {
100+
return nil, nil
101+
}
102+
if u.Scheme == "http" && port == "80" || u.Scheme == "https" && port == "443" {
103+
u.Host = host
104+
}
105+
}
106+
url := u.String()
96107
if res, err := downloader.Cached(url, downloader.WithCacheDir(cacheDir)); err == nil {
97108
if resp, err := sendFile(req, res.CachePath, res.LastModified, res.ContentType); err == nil {
98109
return nil, resp

0 commit comments

Comments
 (0)