{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/18117","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/18117/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/18117/comments","events_url":"https://api.github.com/repos/golang/go/issues/18117/events","html_url":"https://github.com/golang/go/issues/18117","id":192644932,"number":18117,"title":"net/http: Request.Write and Transport differ in Content-Length strictness","user":{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false},"labels":[{"id":373401956,"url":"https://api.github.com/repos/golang/go/labels/NeedsDecision","name":"NeedsDecision","color":"ededed","default":false}],"state":"open","locked":false,"assignee":{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false},"assignees":[{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/49","html_url":"https://github.com/golang/go/milestones/Go1.9","labels_url":"https://api.github.com/repos/golang/go/milestones/49/labels","id":2053058,"number":49,"title":"Go1.9","description":"","creator":{"login":"rsc","id":104030,"avatar_url":"https://avatars.githubusercontent.com/u/104030?v=3","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":293,"closed_issues":18,"state":"open","created_at":"2016-10-06T18:17:55Z","updated_at":"2016-11-30T23:29:48Z","due_on":"2017-07-31T00:00:00Z","closed_at":null},"comments":7,"created_at":"2016-11-30T18:38:51Z","updated_at":"2016-12-01T01:10:37Z","closed_at":null,"body":"Since Go 1 (1.0), there has been this line in transfer.go:\r\n\r\nhttps://github.com/golang/go/blob/release-branch.go1/src/pkg/net/http/transfer.go\r\n\r\n```go\r\n\t\tif rr.ContentLength != 0 && rr.Body == nil {\r\n\t\t\treturn nil, fmt.Errorf(\"http: Request.ContentLength=%d with nil Body\", rr.ContentLength)\r\n\t\t}\r\n```\r\n\r\nWhich causes a Request.Write of a Request with a nil Body and non-zero length to fail.\r\n\r\nBut the Transport accepts that, and makes a nil Body imply a ContentLength of 0.\r\n\r\nThis program should probably have the same output:\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"bytes\"\r\n\t\"log\"\r\n\t\"net/http\"\r\n\t\"net/http/httputil\"\r\n)\r\n\r\nfunc main() {\r\n\treq, _ := http.NewRequest(\"GET\", \"http://foo.com/\", nil)\r\n\treq.Body = nil\r\n\treq.ContentLength = -1\r\n\r\n\t// Using Request.Write\r\n\tvar writeBuf bytes.Buffer\r\n\tif err := req.Write(&writeBuf); err != nil {\r\n\t\tlog.Printf(\"Request.Write = %v\", err)\r\n\t} else {\r\n\t\tlog.Printf(\"Request.Write = %s\", writeBuf.Bytes())\r\n\t}\r\n\r\n\t// Using Transport (DumpRequestOut uses Transport)\r\n\tdump, err := httputil.DumpRequestOut(req, true)\r\n\tif err != nil {\r\n\t\tlog.Printf(\"Dump = %v\", err)\r\n\t} else {\r\n\t\tlog.Printf(\"Dump = %s\", dump)\r\n\t}\r\n}\r\n```\r\n\r\nBut it says:\r\n\r\n```\r\n2016/11/30 18:36:14 Request.Write = http: Request.ContentLength=-1 with nil Body\r\n2016/11/30 18:36:14 Dump = GET / HTTP/1.1\r\nHost: foo.com\r\nUser-Agent: Go-http-client/1.1\r\nTransfer-Encoding: chunked\r\nAccept-Encoding: gzip\r\n\r\n```\r\n\r\nFor Go tip, Go 1.7, Go 1.6, etc.\r\n\r\nDecide whether this is okay or we should fix.\r\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/264048601","html_url":"https://github.com/golang/go/issues/18117#issuecomment-264048601","issue_url":"https://api.github.com/repos/golang/go/issues/18117","id":264048601,"user":{"login":"ggaaooppeenngg","id":4769989,"avatar_url":"https://avatars.githubusercontent.com/u/4769989?v=3","gravatar_id":"","url":"https://api.github.com/users/ggaaooppeenngg","html_url":"https://github.com/ggaaooppeenngg","followers_url":"https://api.github.com/users/ggaaooppeenngg/followers","following_url":"https://api.github.com/users/ggaaooppeenngg/following{/other_user}","gists_url":"https://api.github.com/users/ggaaooppeenngg/gists{/gist_id}","starred_url":"https://api.github.com/users/ggaaooppeenngg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ggaaooppeenngg/subscriptions","organizations_url":"https://api.github.com/users/ggaaooppeenngg/orgs","repos_url":"https://api.github.com/users/ggaaooppeenngg/repos","events_url":"https://api.github.com/users/ggaaooppeenngg/events{/privacy}","received_events_url":"https://api.github.com/users/ggaaooppeenngg/received_events","type":"User","site_admin":false},"created_at":"2016-12-01T01:10:37Z","updated_at":"2016-12-01T01:10:37Z","body":"```\r\npackage main\r\n\r\nimport (\r\n       \t\"io\"\r\n       \t\"net/http\"\r\n)\r\n\r\nvar AnyUserImplementReader = anyUserImplementReader{}\r\n\r\ntype anyUserImplementReader struct{}\r\n\r\nfunc (anyUserImplementReader) Read([]byte) (int, error)         { return 0, io.EOF }\r\nfunc (anyUserImplementReader) Close() error                     { return nil }\r\nfunc (anyUserImplementReader) WriteTo(io.Writer) (int64, error) { return 0, nil }\r\n\r\nfunc main() {\r\n       \treq, err := http.NewRequest(\"GET\", \"http://www.example.com\", AnyUserImplementReader)\r\n       \tif err != nil {\r\n       \t\tpanic(err)\r\n       \t}\r\n       \treq.Body = nil\r\n       \tres, err := http.DefaultClient.Do(req)\r\n       \tif err != nil {\r\n       \t\tpanic(err)\r\n       \t}\r\n       \tdefer res.Body.Close()\r\n}\r\n```\r\n\r\nAny user implemented reader that is not in the list of ` *bytes.Buffer`,`*bytes.Reader`,`*strings.Reader`"}}
{"actor":{"display_login":"ggaaooppeenngg"}}