{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/45128984","id":45128984,"diff_hunk":"@@ -34,6 +36,124 @@ import (\n \t\"k8s.io/kubernetes/pkg/api/rest\"\n )\n \n+func calculateContentLength(reqBody string, transferEncodings []string) int64 {\n+\tif len(transferEncodings) == 0 || (len(transferEncodings) == 1 && transferEncodings[0] == \"identity\") {\n+\t\treturn int64(len(reqBody))\n+\t}\n+\t// RFC2616 section 4.4: The Content-Length header field MUST NOT be sent if these two lengths\n+\t// are different (i.e., if a Transfer-Encoding header field is present).\n+\treturn int64(-1)\n+}\n+\n+func shouldGzip(transferEncodings []string) bool {\n+\tfor _, encoding := range transferEncodings {\n+\t\tif encoding == \"gzip\" {\n+\t\t\treturn true\n+\t\t}\n+\t}\n+\treturn false\n+}\n+\n+func TestProxyRequestContentLengthAndTransferEncoding(t *testing.T) {\n+\tserverResponse := \"got response\"\n+\ttable := []struct {\n+\t\ttransferEncodings []string\n+\t\tcontentEncoding   string\n+\t\treqBody           string\n+\t\treqNamespace      string\n+\t}{\n+\t\t{[]string{}, \"\", \"\", \"default\"},\n+\t\t{[]string{\"identity\"}, \"\", \"question\", \"default\"},\n+\t\t{[]string{\"chunked\"}, \"\", \"question\", \"default\"},\n+\t\t// RFC2616 section-3.6: Whenever a transfer-coding is applied to a message-body, the set of\n+\t\t// transfer-codings MUST include \"chunked\", unless the message is terminated by closing the\n+\t\t// connection.\n+\t\t{[]string{\"chunked\", \"gzip\"}, \"gzip\", \"qqqqqqqqqquestion\", \"default\"},\n+\t}\n+\n+\tfor _, item := range table {\n+\t\tdownstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {\n+\t\t\tfmt.Println(\"CHAO: downstream got header: \", req.Header)\n+\t\t\texpectedContentLength := calculateContentLength(item.reqBody, item.transferEncodings)\n+\t\t\tif e, a := expectedContentLength, req.ContentLength; e != a {\n+\t\t\t\tt.Errorf(\"expected %v, got %v\", e, a)\n+\t\t\t}\n+\t\t\t// We expect Content-Length header field be set\n+\t\t\tif expectedContentLength != -1 {\n+\t\t\t\tcontentLengthInHeader, err := strconv.Atoi(req.Header.Get(\"Content-Length\"))\n+\t\t\t\tif err != nil {\n+\t\t\t\t\tt.Errorf(\"unexpected error: %v\", err)\n+\t\t\t\t}\n+\t\t\t\tif e, a := expectedContentLength, int64(contentLengthInHeader); e != a {\n+\t\t\t\t\tt.Errorf(\"expected %v, got %v\", e, a)\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t// The http library will strip the \"Transfer-Encoding\" field from request.Header.\n+\t\t\tif e, a := \"\", req.Header.Get(\"Transfer-Encoding\"); e != a {\n+\t\t\t\tt.Errorf(\"expected %v, got %v\", e, a)\n+\t\t\t}\n+\t\t\tif e, a := item.contentEncoding, req.Header.Get(\"Content-Encoding\"); e != a {","path":"pkg/apiserver/proxy_test.go","position":77,"original_position":77,"commit_id":"9690029a21e6ca9891cc60ca965635ca8a5fb8bb","original_commit_id":"9690029a21e6ca9891cc60ca965635ca8a5fb8bb","user":{"login":"caesarxuchao","id":2823529,"avatar_url":"https://avatars.githubusercontent.com/u/2823529?v=3","gravatar_id":"","url":"https://api.github.com/users/caesarxuchao","html_url":"https://github.com/caesarxuchao","followers_url":"https://api.github.com/users/caesarxuchao/followers","following_url":"https://api.github.com/users/caesarxuchao/following{/other_user}","gists_url":"https://api.github.com/users/caesarxuchao/gists{/gist_id}","starred_url":"https://api.github.com/users/caesarxuchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caesarxuchao/subscriptions","organizations_url":"https://api.github.com/users/caesarxuchao/orgs","repos_url":"https://api.github.com/users/caesarxuchao/repos","events_url":"https://api.github.com/users/caesarxuchao/events{/privacy}","received_events_url":"https://api.github.com/users/caesarxuchao/received_events","type":"User","site_admin":false},"body":"The Go library doesn't change the \"Content-Encoding\" field.","created_at":"2015-11-17T22:05:01Z","updated_at":"2015-11-17T22:05:01Z","html_url":"https://github.com/kubernetes/kubernetes/pull/16400#discussion_r45128984","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/16400","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/45128984"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/16400#discussion_r45128984"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/16400"}}},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/16400","id":48952571,"html_url":"https://github.com/kubernetes/kubernetes/pull/16400","diff_url":"https://github.com/kubernetes/kubernetes/pull/16400.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/16400.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/16400","number":16400,"state":"open","locked":false,"title":"Copy the request ContentLength and TransferEncoding field in proxy","user":{"login":"caesarxuchao","id":2823529,"avatar_url":"https://avatars.githubusercontent.com/u/2823529?v=3","gravatar_id":"","url":"https://api.github.com/users/caesarxuchao","html_url":"https://github.com/caesarxuchao","followers_url":"https://api.github.com/users/caesarxuchao/followers","following_url":"https://api.github.com/users/caesarxuchao/following{/other_user}","gists_url":"https://api.github.com/users/caesarxuchao/gists{/gist_id}","starred_url":"https://api.github.com/users/caesarxuchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caesarxuchao/subscriptions","organizations_url":"https://api.github.com/users/caesarxuchao/orgs","repos_url":"https://api.github.com/users/caesarxuchao/repos","events_url":"https://api.github.com/users/caesarxuchao/events{/privacy}","received_events_url":"https://api.github.com/users/caesarxuchao/received_events","type":"User","site_admin":false},"body":"Thanks to @tiran for identifying the problem and proposing the fix.\r\n\r\n@lavalamp @liggitt \r\n\r\nfix #16093","created_at":"2015-10-28T00:50:21Z","updated_at":"2015-11-17T22:05:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4eb61b4a4a26f98435587eb638c2c3c38bb0f3cb","assignee":{"login":"lavalamp","id":647318,"avatar_url":"https://avatars.githubusercontent.com/u/647318?v=3","gravatar_id":"","url":"https://api.github.com/users/lavalamp","html_url":"https://github.com/lavalamp","followers_url":"https://api.github.com/users/lavalamp/followers","following_url":"https://api.github.com/users/lavalamp/following{/other_user}","gists_url":"https://api.github.com/users/lavalamp/gists{/gist_id}","starred_url":"https://api.github.com/users/lavalamp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lavalamp/subscriptions","organizations_url":"https://api.github.com/users/lavalamp/orgs","repos_url":"https://api.github.com/users/lavalamp/repos","events_url":"https://api.github.com/users/lavalamp/events{/privacy}","received_events_url":"https://api.github.com/users/lavalamp/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/16400/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/16400/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/16400/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/9690029a21e6ca9891cc60ca965635ca8a5fb8bb","head":{"label":"caesarxuchao:fix-proxy-content-length","ref":"fix-proxy-content-length","sha":"9690029a21e6ca9891cc60ca965635ca8a5fb8bb","user":{"login":"caesarxuchao","id":2823529,"avatar_url":"https://avatars.githubusercontent.com/u/2823529?v=3","gravatar_id":"","url":"https://api.github.com/users/caesarxuchao","html_url":"https://github.com/caesarxuchao","followers_url":"https://api.github.com/users/caesarxuchao/followers","following_url":"https://api.github.com/users/caesarxuchao/following{/other_user}","gists_url":"https://api.github.com/users/caesarxuchao/gists{/gist_id}","starred_url":"https://api.github.com/users/caesarxuchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caesarxuchao/subscriptions","organizations_url":"https://api.github.com/users/caesarxuchao/orgs","repos_url":"https://api.github.com/users/caesarxuchao/repos","events_url":"https://api.github.com/users/caesarxuchao/events{/privacy}","received_events_url":"https://api.github.com/users/caesarxuchao/received_events","type":"User","site_admin":false},"repo":{"id":34024678,"name":"kubernetes","full_name":"caesarxuchao/kubernetes","owner":{"login":"caesarxuchao","id":2823529,"avatar_url":"https://avatars.githubusercontent.com/u/2823529?v=3","gravatar_id":"","url":"https://api.github.com/users/caesarxuchao","html_url":"https://github.com/caesarxuchao","followers_url":"https://api.github.com/users/caesarxuchao/followers","following_url":"https://api.github.com/users/caesarxuchao/following{/other_user}","gists_url":"https://api.github.com/users/caesarxuchao/gists{/gist_id}","starred_url":"https://api.github.com/users/caesarxuchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caesarxuchao/subscriptions","organizations_url":"https://api.github.com/users/caesarxuchao/orgs","repos_url":"https://api.github.com/users/caesarxuchao/repos","events_url":"https://api.github.com/users/caesarxuchao/events{/privacy}","received_events_url":"https://api.github.com/users/caesarxuchao/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/caesarxuchao/kubernetes","description":"Container Cluster Manager from Google","fork":true,"url":"https://api.github.com/repos/caesarxuchao/kubernetes","forks_url":"https://api.github.com/repos/caesarxuchao/kubernetes/forks","keys_url":"https://api.github.com/repos/caesarxuchao/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caesarxuchao/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caesarxuchao/kubernetes/teams","hooks_url":"https://api.github.com/repos/caesarxuchao/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/caesarxuchao/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/caesarxuchao/kubernetes/events","assignees_url":"https://api.github.com/repos/caesarxuchao/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/caesarxuchao/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/caesarxuchao/kubernetes/tags","blobs_url":"https://api.github.com/repos/caesarxuchao/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caesarxuchao/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caesarxuchao/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/caesarxuchao/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caesarxuchao/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/caesarxuchao/kubernetes/languages","stargazers_url":"https://api.github.com/repos/caesarxuchao/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/caesarxuchao/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/caesarxuchao/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/caesarxuchao/kubernetes/subscription","commits_url":"https://api.github.com/repos/caesarxuchao/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/caesarxuchao/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/caesarxuchao/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/caesarxuchao/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/caesarxuchao/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/caesarxuchao/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caesarxuchao/kubernetes/merges","archive_url":"https://api.github.com/repos/caesarxuchao/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caesarxuchao/kubernetes/downloads","issues_url":"https://api.github.com/repos/caesarxuchao/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/caesarxuchao/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/caesarxuchao/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/caesarxuchao/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caesarxuchao/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/caesarxuchao/kubernetes/releases{/id}","created_at":"2015-04-15T23:57:43Z","updated_at":"2015-05-07T17:21:06Z","pushed_at":"2015-11-17T21:58:47Z","git_url":"git://github.com/caesarxuchao/kubernetes.git","ssh_url":"git@github.com:caesarxuchao/kubernetes.git","clone_url":"https://github.com/caesarxuchao/kubernetes.git","svn_url":"https://github.com/caesarxuchao/kubernetes","homepage":"http://kubernetes.io","size":137665,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"a10a2f0e2b7535c88d9c23b69e1028e2fa47eb93","user":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"repo":{"id":20580498,"name":"kubernetes","full_name":"kubernetes/kubernetes","owner":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kubernetes/kubernetes","description":"Container Cluster Manager from Google","fork":false,"url":"https://api.github.com/repos/kubernetes/kubernetes","forks_url":"https://api.github.com/repos/kubernetes/kubernetes/forks","keys_url":"https://api.github.com/repos/kubernetes/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kubernetes/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kubernetes/kubernetes/teams","hooks_url":"https://api.github.com/repos/kubernetes/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/kubernetes/kubernetes/events","assignees_url":"https://api.github.com/repos/kubernetes/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/kubernetes/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/kubernetes/kubernetes/tags","blobs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kubernetes/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/kubernetes/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/kubernetes/kubernetes/languages","stargazers_url":"https://api.github.com/repos/kubernetes/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/kubernetes/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/kubernetes/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/kubernetes/kubernetes/subscription","commits_url":"https://api.github.com/repos/kubernetes/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/kubernetes/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/kubernetes/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/kubernetes/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kubernetes/kubernetes/merges","archive_url":"https://api.github.com/repos/kubernetes/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kubernetes/kubernetes/downloads","issues_url":"https://api.github.com/repos/kubernetes/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/kubernetes/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/kubernetes/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kubernetes/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/kubernetes/kubernetes/releases{/id}","created_at":"2014-06-06T22:56:04Z","updated_at":"2015-11-17T20:50:05Z","pushed_at":"2015-11-17T21:58:50Z","git_url":"git://github.com/kubernetes/kubernetes.git","ssh_url":"git@github.com:kubernetes/kubernetes.git","clone_url":"https://github.com/kubernetes/kubernetes.git","svn_url":"https://github.com/kubernetes/kubernetes","homepage":"http://kubernetes.io","size":286489,"stargazers_count":11306,"watchers_count":11306,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2981,"mirror_url":null,"open_issues_count":2324,"forks":2981,"open_issues":2324,"watchers":11306,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/16400"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/16400"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/16400"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/16400/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/16400/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/16400/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/9690029a21e6ca9891cc60ca965635ca8a5fb8bb"}}}}