Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Dec 26, 2024
1 parent 6efcbf7 commit cf2068f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
27 changes: 26 additions & 1 deletion crproxy_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (c *CRProxy) cacheBlobResponse(rw http.ResponseWriter, r *http.Request, inf
}

func (c *CRProxy) cacheBlobContent(ctx context.Context, r *http.Request, blobPath string, info *PathInfo) (int64, error) {
r.Method = http.MethodGet
cli := c.getClientset(info.Host, info.Image)
resp, err := c.doWithAuth(cli, r.WithContext(ctx), info.Host)
if err != nil {
Expand All @@ -140,7 +141,31 @@ func (c *CRProxy) cacheBlobContent(ctx context.Context, r *http.Request, blobPat
return 0, errcode.ErrorCodeDenied
}

if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
if resp.StatusCode < http.StatusOK {
if c.logger != nil {
c.logger.Println("origin blob response 1xx", info.Host, info.Image, resp.StatusCode, dumpResponse(resp))
}
return 0, errcode.ErrorCodeUnknown.WithMessage(fmt.Sprintf("Source response code %d", resp.StatusCode))
}

if resp.StatusCode >= http.StatusMultipleChoices && resp.StatusCode < http.StatusBadRequest {
if c.logger != nil {
c.logger.Println("origin blob response 3xx", info.Host, info.Image, resp.StatusCode, dumpResponse(resp))
}
return 0, errcode.ErrorCodeUnknown.WithMessage(fmt.Sprintf("Source response code %d", resp.StatusCode))
}

if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode < http.StatusInternalServerError {
if c.logger != nil {
c.logger.Println("origin blob response 4xx", info.Host, info.Image, resp.StatusCode, dumpResponse(resp))
}
return 0, errcode.ErrorCodeUnknown.WithMessage(fmt.Sprintf("Source response code %d", resp.StatusCode))
}

if resp.StatusCode >= http.StatusInternalServerError {
if c.logger != nil {
c.logger.Println("origin blob response 5xx", info.Host, info.Image, resp.StatusCode, dumpResponse(resp))
}
return 0, errcode.ErrorCodeUnknown.WithMessage(fmt.Sprintf("Source response code %d", resp.StatusCode))
}

Expand Down
4 changes: 2 additions & 2 deletions crproxy_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *CRProxy) cacheManifestResponse(rw http.ResponseWriter, r *http.Request,
return
}
if c.logger != nil {
c.logger.Println("origin manifest response 4xx", info.Host, info.Image, err, dumpResponse(resp))
c.logger.Println("origin manifest response 4xx", info.Host, info.Image)
}
} else if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusInternalServerError {
if c.fallbackServeCachedManifest(rw, r, info) {
Expand All @@ -80,7 +80,7 @@ func (c *CRProxy) cacheManifestResponse(rw http.ResponseWriter, r *http.Request,
return
}
if c.logger != nil {
c.logger.Println("origin manifest response 5xx", info.Host, info.Image, err, dumpResponse(resp))
c.logger.Println("origin manifest response 5xx", info.Host, info.Image)
}
}

Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ func isDomainName(s string) bool {
}

func dumpResponse(resp *http.Response) string {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 100))
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1000))
return fmt.Sprintf("%d %d %q", resp.StatusCode, resp.ContentLength, string(body))
}

0 comments on commit cf2068f

Please sign in to comment.