Currently, I am confronting to strange problem with reuse tcp connection.
The problem is describe in more detail here
https://github.com/go-kit/kit/issues/249
In the nutshell:
when I use httpclient with server that send me response, the httpclient
closes the tcp connection
except if I set the classic defer io.Copy(ioutil.Discard, r.Body) (as
describe here
https://groups.google.com/forum/#!search/golang$20json$20decode$20$20io.Copy/golang-nuts/4Rr8BYVKrAI/ZrJJFTNleekJ)
Normally I just read the response with
json.NewDecoder(response.Body).Decode(&something)
The trace from wireshark:
GET /api/v1/state HTTP/1.1
Host: 10.130.145.94:8401
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip
Connection: keep-alive
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 04 May 2016 09:05:12 GMT
1b
{"state":"OK","message":""}
But this io.Copy doesn't read nothing because:
defer func() {
b := new(bytes.Buffer)
io.Copy(b, response.Body)
fmt.Println("--------------->", b.Len())
fmt.Println(hex.Dump(b.Bytes()))
fmt.Println("###############>")
}()
log
---------------> 0
###############>
My current comprehension, that is json decoder doesn't read the last 0 that
indicates the end of chunked response.
or do I miss something?
Do I have to put defer io.Copy(ioutil.Discard, r.Body)?
Thx in adv
Jérôme
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.