Skip to content

Commit

Permalink
Normalize url string before using cache
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
  • Loading branch information
afbjorklund committed Oct 18, 2024
1 parent 6642b4d commit c4f62e2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/hostagent/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"
"time"

"github.com/lima-vm/lima/pkg/downloader"
Expand Down Expand Up @@ -92,7 +93,17 @@ func listenAndServe(opts ServerOptions) (*http.Server, error) {
proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*$"))).
HandleConnect(goproxy.AlwaysMitm)
proxy.OnRequest().DoFunc(func(req *http.Request, _ *goproxy.ProxyCtx) (*http.Request, *http.Response) {
url := req.URL.String()
u := req.URL
if strings.Contains(u.Host, ":") {
host, port, err := net.SplitHostPort(u.Host)
if err != nil {
return nil, nil
}
if u.Scheme == "http" && port == "80" || u.Scheme == "https" && port == "443" {
u.Host = host
}
}
url := u.String()
if res, err := downloader.Cached(url, downloader.WithCacheDir(cacheDir)); err == nil {
if resp, err := sendFile(req, res.CachePath, res.LastModified, res.ContentType); err == nil {
return nil, resp
Expand Down

0 comments on commit c4f62e2

Please sign in to comment.