Skip to content
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

Merged
merged 2 commits into from
Apr 27, 2022

Conversation

notanatol
Copy link
Contributor

@notanatol notanatol commented Apr 27, 2022

Checklist

Description

If decompressed-content-length fails try the normal one before stopping.


This change is Reviewable

Copy link
Contributor

@mrekucci mrekucci left a 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
}
// ...

Copy link
Contributor Author

@notanatol notanatol left a 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

@notanatol notanatol requested a review from mrekucci April 27, 2022 15:14
@acud acud changed the title fix: add fallback conversion fix: add fallback content length check in middleware Apr 27, 2022
@acud acud merged commit bdc8416 into master Apr 27, 2022
@acud acud deleted the content-len-conversion branch April 27, 2022 17:05
@acud acud added this to the 1.6.0 milestone May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants