-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add fallback content length check in middleware #2907
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on @acud)
pkg/api/api.go
line 417 at r1 (raw file):
case http.MethodGet: hdr := w.Header().Get("Decompressed-Content-Length") contentLength, err := strconv.Atoi(hdr)
There is no need to do the conversion if the header is not present. I'd recommend the following checks:
// ...
hdr := w.Header().Get("Decompressed-Content-Length")
if hdr == "" {
s.logger.Debug("api: decompressed content length header not found")
hdr = w.Header().Get("Content-Length")
if hdr == "" {
s.logger.Debug("api: content length header not found")
return
}
}
contentLength, err := strconv.Atoi(hdr)
if err != nil {
s.logger.Debugf("api: content length: '%s', int conversion failed: %v", hdr, err)
return
}
// ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on @acud)
pkg/api/api.go
line 417 at r1 (raw file):
Previously, mrekucci wrote…
There is no need to do the conversion if the header is not present. I'd recommend the following checks:
// ... hdr := w.Header().Get("Decompressed-Content-Length") if hdr == "" { s.logger.Debug("api: decompressed content length header not found") hdr = w.Header().Get("Content-Length") if hdr == "" { s.logger.Debug("api: content length header not found") return } } contentLength, err := strconv.Atoi(hdr) if err != nil { s.logger.Debugf("api: content length: '%s', int conversion failed: %v", hdr, err) return } // ...
replaced with this version
Checklist
Description
If
decompressed-content-length
fails try the normal one before stopping.This change is