Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Call WriteHeader before writing
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov committed Jun 9, 2021
1 parent 6783b91 commit bd2ce55
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions internal/http_cache/http_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ func proxyDownloadFromURL(w http.ResponseWriter, url string) {
bytesRead, err := io.Copy(w, resp.Body)
if err != nil {
log.Printf("Proxying cache download for %s failed with %v\n", url, err)
w.WriteHeader(http.StatusInternalServerError)
} else {
log.Printf("Proxying cache %s succeded! Proxies %d bytes!\n", url, bytesRead)
w.WriteHeader(http.StatusOK)
}
}

Expand All @@ -168,16 +166,16 @@ func uploadCache(w http.ResponseWriter, r *http.Request, cacheKey string) {
if err != nil {
errorMsg := fmt.Sprintf("Failed to initialized uploading of %s cache! %s", cacheKey, err)
log.Print(errorMsg)
w.Write([]byte(errorMsg))
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(errorMsg))
return
}
post, err := httpProxyClient.Post(response.Url, "application/octet-stream", bufio.NewReader(r.Body))
if err != nil {
errorMsg := fmt.Sprintf("Failed to proxy upload of %s cache! %s", cacheKey, err)
log.Print(errorMsg)
w.Write([]byte(errorMsg))
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(errorMsg))
return
}
w.WriteHeader(post.StatusCode)
Expand Down

0 comments on commit bd2ce55

Please sign in to comment.