Set a io.Reader in http.NewRequest and do a http request, I found that 
someone reads the io.Reader even after the http request done.

Is it a correct behaviour? And is it documented?

My client code is

package main
import (
    "log"
    "net/http"
    "time")
type reader struct{}
func (r reader) Read(p []byte) (int, error) {
    log.Println("READ")
    return len(p), nil}
func (r reader) Close() error {
    log.Println("CLOSE")
    return nil}
func main() {
    r := reader{}
    req, _ := http.NewRequest("GET", "http://localhost:12306/";, r)
    req.ContentLength = 1896240
    resp, err := http.DefaultClient.Do(req)
    if resp != nil {
        resp.Body.Close()
    }
    log.Println("http.DefaultClient.Do", err)
    time.Sleep(1e9)}

and the server localhost:12306 simple write an http code and do nothing.

This is the output of the program.

[sunrunaway:/tmp]$ go run test.go 
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 READ
2016/07/25 13:04:32 http.DefaultClient.Do <nil>
2016/07/25 13:04:32 READ

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to