xinsnake / go-http-digest-auth-client

Golang Http Digest Authentication Client
BSD 2-Clause "Simplified" License
41 stars 68 forks source link

response body not close #4

Closed huaxiansha closed 7 years ago

huaxiansha commented 7 years ago

response body not close , whitch created in func (dr DigestRequest) Execute() (resp http.Response, err error)

user only can get and close the response body created in func (dr DigestRequest) executeRequest(authString string) (http.Response, error), but the response body created in func (dr DigestRequest) Execute() (resp http.Response, err error) is not close anywhere.

i think can add resp.Body.Close() after line 102 in file digest_auth_client.go, is it right

xinsnake commented 7 years ago

Hi @huaxiansha thanks for your suggesting, it does cause a memory leak problem if not closed properly.

I don't think where you mentioned was the correct place to put it, and I implemented Line 87 and Line 147 which should fix this problem.

Thanks for raising this issue.

huaxiansha commented 7 years ago

As far as i know, the resp.Body will not be used after resp.Body.Close() So, I think resp.Body should be closed by user because user may need to get the content of resp.Body.

xinsnake commented 7 years ago

@huaxiansha sorry it's been a while and I forgot what was the mechanism. You are correct that my previous fix was wrong. After looking into it in more detail I have added the resp.Body.Close() into only when a 401 is returned, and if it's normal response it should not close the body.