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

look at the body to determine if it has content or not #149

Merged
merged 1 commit into from
Jul 18, 2019
Merged

Conversation

casualjim
Copy link
Member

fixes #148

Signed-off-by: Ivan Porto Carrero ivan@flanders.co.nz

Signed-off-by: Ivan Porto Carrero <ivan@flanders.co.nz>
@codecov
Copy link

codecov bot commented Jul 10, 2019

Codecov Report

Merging #149 into master will decrease coverage by 0.31%.
The diff coverage is 54.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #149      +/-   ##
==========================================
- Coverage    80.9%   80.59%   -0.32%     
==========================================
  Files          40       40              
  Lines        2299     2329      +30     
==========================================
+ Hits         1860     1877      +17     
- Misses        337      347      +10     
- Partials      102      105       +3
Impacted Files Coverage Δ
request.go 57.14% <54.83%> (-0.55%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58872d9...09f01ee. Read the comment docs.

if p.underlying.Buffered() > 0 {
return true
}
b, err := p.underlying.Peek(1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this return pre-decoded bytes? If so, we may need to be careful about the the fact that an empty entity-body in chunked transfer-encoding is represented as a single ascii "0" after headers, and before the terminating CRLF.

Something like:

..headers...
transfer-encoding: chunked\r\n
\r\n
0\r\n

If this underlying was given bytes that already handles the transfer "decoding" then we should be safe here, but I can't tell exactly from the surrounding code just yet.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Go documentation is slightly comforting, but not specific:

 178         // For server requests, the Request Body is always non-nil
 179         // but will return EOF immediately when no body is present.
 180         // The Server will close the request body. The ServeHTTP
 181         // Handler does not need to.
 182         Body io.ReadCloser

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great: golang/go#11675 (comment) sounds like it handles transfer encodings, or at least it did 4 years ago.

return false
}

rdr := newPeekingReader(r.Body)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my concern below is invalid if r.Body represents an entity-body after all transfer-encodings have been applied. but if it does not, then I think the peek(1) will observe ascii "0" (end of chunk marker) and mistakenly assume there is a body.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the go stdlib takes care of this part

@jhewes
Copy link

jhewes commented Jul 18, 2019

I have run a test with the patch and I can confirm it has resolved the issue we were seeing.

Thank you!

@casualjim casualjim merged commit 7a84b65 into master Jul 18, 2019
@casualjim casualjim deleted the peek-body branch July 18, 2019 23:29
kzys pushed a commit to kzys/runtime that referenced this pull request Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transfer-Encoding: chunked does not imply a body is present
3 participants