diff --git a/crproxy_blob.go b/crproxy_blob.go index 5ceed5a..b404a47 100644 --- a/crproxy_blob.go +++ b/crproxy_blob.go @@ -145,7 +145,7 @@ func (c *CRProxy) cacheBlobContent(ctx context.Context, r *http.Request, blobPat return 0, errcode.ErrorCodeDenied } - if resp.StatusCode < 200 || resp.StatusCode >= 300 { + if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices { return 0, errcode.ErrorCodeUnknown.WithMessage(fmt.Sprintf("Source response code %d", resp.StatusCode)) } diff --git a/crproxy_manifest.go b/crproxy_manifest.go index 46323b7..511ed50 100644 --- a/crproxy_manifest.go +++ b/crproxy_manifest.go @@ -61,7 +61,7 @@ func (c *CRProxy) cacheManifestResponse(rw http.ResponseWriter, r *http.Request, return } - if resp.StatusCode >= http.StatusInternalServerError { + if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusBadRequest { if c.cachedManifest(rw, r, info, false) { if c.logger != nil { c.logger.Println("origin manifest response 5xx, but hit caches", info.Host, info.Image, err, dumpResponse(resp)) @@ -81,23 +81,28 @@ func (c *CRProxy) cacheManifestResponse(rw http.ResponseWriter, r *http.Request, header[key] = v } + rw.WriteHeader(resp.StatusCode) + if r.Method == http.MethodHead { - rw.WriteHeader(resp.StatusCode) return } - body, err := io.ReadAll(resp.Body) - if err != nil { - c.errorResponse(rw, r, err) - return - } - err = c.cacheManifestContent(context.Background(), info, body) - if err != nil { - c.errorResponse(rw, r, err) - return + if resp.StatusCode >= http.StatusOK || resp.StatusCode < http.StatusMultipleChoices { + body, err := io.ReadAll(resp.Body) + if err != nil { + c.errorResponse(rw, r, err) + return + } + + err = c.cacheManifestContent(context.Background(), info, body) + if err != nil { + c.errorResponse(rw, r, err) + return + } + rw.Write(body) + } else { + io.Copy(rw, resp.Body) } - rw.WriteHeader(resp.StatusCode) - rw.Write(body) } func (c *CRProxy) cacheManifestContent(ctx context.Context, info *PathInfo, content []byte) error {