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

WriteJSON check response write error #1653

Closed
wants to merge 16 commits into from
Closed

WriteJSON check response write error #1653

wants to merge 16 commits into from

Conversation

lpxxn
Copy link

@lpxxn lpxxn commented Nov 20, 2018

we need to check w.Write(jsonBytes) error.

there have an case, i have encountered:
when i write wrong number of response Header Content-Length
the w.Write(jsonBytes) will throw an err "http: wrote more than the declared Content-Length"

w.written += int64(lenData) // ignoring errors, for errorKludge        

if w.contentLength != -1 && w.written > w.contentLength {       

	return 0, ErrContentLength       

}       

but gin did not throw the error, and response body is empty

@codecov
Copy link

codecov bot commented Nov 20, 2018

Codecov Report

Merging #1653 into master will increase coverage by 1.06%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1653      +/-   ##
==========================================
+ Coverage   98.48%   99.55%   +1.06%     
==========================================
  Files          41       23      -18     
  Lines        2042      445    -1597     
==========================================
- Hits         2011      443    -1568     
+ Misses         19        1      -18     
+ Partials       12        1      -11
Impacted Files Coverage Δ
render/json.go 96.96% <33.33%> (+10.48%) ⬆️
render/text.go 100% <0%> (ø) ⬆️
logger.go
debug.go
tree.go
utils.go
response_writer.go
fs.go
response_writer_1.8.go
path.go
... and 12 more

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 b4f5155...1c37d16. Read the comment docs.

@appleboy
Copy link
Member

appleboy commented Nov 22, 2018

@lpxxn Please add the testing case to improve code coverage.

@appleboy appleboy added the bug label Nov 22, 2018
@appleboy appleboy added this to the 1.4 milestone Nov 22, 2018
@lpxxn
Copy link
Author

lpxxn commented Nov 26, 2018

@lpxxn Please add the testing case to improve code coverage.

@appleboy i have write the testing function, check the panic of c.JSON when make wrong Content-Length

gin_test.go Outdated Show resolved Hide resolved
@thinkerou
Copy link
Member

thinkerou commented Jan 20, 2019

#1739 fixed! thanks @lpxxn

@thinkerou thinkerou closed this Jan 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants