FAQ
Hello every body,
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 golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 4, '16 at 9:41a
activeMay 17, '16 at 6:38a
posts3
users2
websitegolang.org

2 users in discussion

Jérôme LAFORGE: 2 posts Peter Waller: 1 post

People

Translate

site design / logo © 2021 Grokbase