Skip to content

Commit

Permalink
fix download url
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin committed Sep 5, 2024
1 parent 58af2f1 commit 86ef72e
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions pkg/cache/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,7 @@ func (s *CacheServer) Get(w http.ResponseWriter, r *http.Request) {
return
}

// overwrite URL with own
baseURL := s.baseURL
if baseURL == "" {
baseURL = fmt.Sprintf("http://%s%s", r.Host, r.RequestURI)
}
downloadURL := fmt.Sprintf("%s/%s/download", baseURL, id)

downloadURL := getDownloadURL(s.baseURL, r)
resp.Object = cache.Object{
ID: id,
Checksum: object.Checksum,
Expand Down Expand Up @@ -135,13 +129,7 @@ func (s *CacheServer) Store(w http.ResponseWriter, r *http.Request) {
return
}

// overwrite URL with own
baseURL := s.baseURL
if baseURL == "" {
baseURL = fmt.Sprintf("http://%s%s", r.Host, r.RequestURI)
}
downloadURL := fmt.Sprintf("%s/%s/download", baseURL, id)

downloadURL := getDownloadURL(s.baseURL, r)
resp.Object = cache.Object{
ID: id,
Checksum: object.Checksum,
Expand All @@ -152,6 +140,14 @@ func (s *CacheServer) Store(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(resp) //nolint:errchkjson
}

func getDownloadURL(baseURL string, r *http.Request) string {
if baseURL != "" {
return fmt.Sprintf("%s/%s/download", baseURL, r.PathValue("id"))
}

return fmt.Sprintf("http://%s%s/download", r.Host, r.RequestURI)
}

// Download returns an object's content given its id
func (s *CacheServer) Download(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
Expand Down

0 comments on commit 86ef72e

Please sign in to comment.