Skip to content

Commit

Permalink
Merge pull request #32 from grafana/fix-dowload-url
Browse files Browse the repository at this point in the history
fix download url
  • Loading branch information
pablochacin authored Sep 5, 2024
2 parents 58af2f1 + 86ef72e commit 5b30579
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 5b30579

Please sign in to comment.