{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/etcd/pulls/comments/45704308","id":45704308,"diff_hunk":"@@ -203,3 +210,42 @@ func maybeSetForwardedFor(req *http.Request) {\n \t}\n \treq.Header.Set(\"X-Forwarded-For\", clientIP)\n }\n+\n+const proxyLoopHeaderKey = \"X-Etcd-Proxy-Hop-Seen-By\"\n+\n+// recordProxy records proxyID and an endpoint in HTTP headers,\n+// in order to detect a proxy loop.\n+func recordProxy(req *http.Request, proxyID string, loc url.URL) {\n+\tpv := proxyID + \"=\" + loc.String()\n+\tif prior, ok := req.Header[proxyLoopHeaderKey]; ok {\n+\t\tpv = strings.Join(prior, \", \") + \", \" + pv\n+\t}\n+\treq.Header.Set(proxyLoopHeaderKey, pv)\n+}\n+\n+// checkProxyLoop detects a proxy loop by passing around proxyID\n+// and endpoints. It returns the repeating endpoint string and\n+// truu if it finds the loop.\n+func (p *reverseProxy) checkProxyLoop(req *http.Request) (string, bool) {\n+\tif prior, ok := req.Header[proxyLoopHeaderKey]; ok {\n+\t\tfor _, v := range strings.Split(prior[0], \", \") {\n+\t\t\tvs := strings.Split(v, \"=\")\n+\t\t\tif len(vs) == 2 {\n+\t\t\t\tif p.proxyID == vs[0] {\n+\t\t\t\t\treturn vs[1], true\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn \"\", false\n+}\n+\n+// banEndpoint bans the URL from reverseProxy's endpoints.\n+func (p *reverseProxy) banEndpoint(rp string) {\n+\tp.director.Lock()\n+\tp.director.bannedEndpoints[rp] = struct{}{}\n+\tp.director.Unlock()\n+\n+\t// update endpoints by calling refresh method.\n+\tp.director.refresh()","path":"proxy/reverse.go","position":72,"original_position":65,"commit_id":"c6ec210b0d777c765c9b63ef1256232544ed6ad5","original_commit_id":"c07ec7532b138c4e997b660b7bab2d90ca12515f","user":{"login":"yichengq","id":2976232,"avatar_url":"https://avatars.githubusercontent.com/u/2976232?v=3","gravatar_id":"","url":"https://api.github.com/users/yichengq","html_url":"https://github.com/yichengq","followers_url":"https://api.github.com/users/yichengq/followers","following_url":"https://api.github.com/users/yichengq/following{/other_user}","gists_url":"https://api.github.com/users/yichengq/gists{/gist_id}","starred_url":"https://api.github.com/users/yichengq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yichengq/subscriptions","organizations_url":"https://api.github.com/users/yichengq/orgs","repos_url":"https://api.github.com/users/yichengq/repos","events_url":"https://api.github.com/users/yichengq/events{/privacy}","received_events_url":"https://api.github.com/users/yichengq/received_events","type":"User","site_admin":false},"body":"I think there is no need to refresh it here, because ban is good enough. moreover, i think this should be a member function of `director`","created_at":"2015-11-24T07:39:21Z","updated_at":"2015-11-24T07:39:21Z","html_url":"https://github.com/coreos/etcd/pull/3645#discussion_r45704308","pull_request_url":"https://api.github.com/repos/coreos/etcd/pulls/3645","_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd/pulls/comments/45704308"},"html":{"href":"https://github.com/coreos/etcd/pull/3645#discussion_r45704308"},"pull_request":{"href":"https://api.github.com/repos/coreos/etcd/pulls/3645"}}},"pull_request":{"url":"https://api.github.com/repos/coreos/etcd/pulls/3645","id":46907266,"html_url":"https://github.com/coreos/etcd/pull/3645","diff_url":"https://github.com/coreos/etcd/pull/3645.diff","patch_url":"https://github.com/coreos/etcd/pull/3645.patch","issue_url":"https://api.github.com/repos/coreos/etcd/issues/3645","number":3645,"state":"open","locked":false,"title":"proxy: check loop with proxyID, endpoint in header","user":{"login":"gyuho","id":6799218,"avatar_url":"https://avatars.githubusercontent.com/u/6799218?v=3","gravatar_id":"","url":"https://api.github.com/users/gyuho","html_url":"https://github.com/gyuho","followers_url":"https://api.github.com/users/gyuho/followers","following_url":"https://api.github.com/users/gyuho/following{/other_user}","gists_url":"https://api.github.com/users/gyuho/gists{/gist_id}","starred_url":"https://api.github.com/users/gyuho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gyuho/subscriptions","organizations_url":"https://api.github.com/users/gyuho/orgs","repos_url":"https://api.github.com/users/gyuho/repos","events_url":"https://api.github.com/users/gyuho/events{/privacy}","received_events_url":"https://api.github.com/users/gyuho/received_events","type":"User","site_admin":false},"body":"This detects proxy loop by passing around proxyID and endpoints in HTTP header.\r\nOnce it detects the loop, it updates proxy's endpoints.\r\n\r\nFixes #3317.\r\n\r\n(*updated PR description according the most recent commit)","created_at":"2015-10-06T14:08:53Z","updated_at":"2015-11-24T07:39:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a939af359e7c10466b34c2b002713d53e2fdbc38","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coreos/etcd/pulls/3645/commits","review_comments_url":"https://api.github.com/repos/coreos/etcd/pulls/3645/comments","review_comment_url":"https://api.github.com/repos/coreos/etcd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coreos/etcd/issues/3645/comments","statuses_url":"https://api.github.com/repos/coreos/etcd/statuses/c6ec210b0d777c765c9b63ef1256232544ed6ad5","head":{"label":"gyuho:check_proxy_loop","ref":"check_proxy_loop","sha":"c6ec210b0d777c765c9b63ef1256232544ed6ad5","user":{"login":"gyuho","id":6799218,"avatar_url":"https://avatars.githubusercontent.com/u/6799218?v=3","gravatar_id":"","url":"https://api.github.com/users/gyuho","html_url":"https://github.com/gyuho","followers_url":"https://api.github.com/users/gyuho/followers","following_url":"https://api.github.com/users/gyuho/following{/other_user}","gists_url":"https://api.github.com/users/gyuho/gists{/gist_id}","starred_url":"https://api.github.com/users/gyuho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gyuho/subscriptions","organizations_url":"https://api.github.com/users/gyuho/orgs","repos_url":"https://api.github.com/users/gyuho/repos","events_url":"https://api.github.com/users/gyuho/events{/privacy}","received_events_url":"https://api.github.com/users/gyuho/received_events","type":"User","site_admin":false},"repo":{"id":42982042,"name":"etcd","full_name":"gyuho/etcd","owner":{"login":"gyuho","id":6799218,"avatar_url":"https://avatars.githubusercontent.com/u/6799218?v=3","gravatar_id":"","url":"https://api.github.com/users/gyuho","html_url":"https://github.com/gyuho","followers_url":"https://api.github.com/users/gyuho/followers","following_url":"https://api.github.com/users/gyuho/following{/other_user}","gists_url":"https://api.github.com/users/gyuho/gists{/gist_id}","starred_url":"https://api.github.com/users/gyuho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gyuho/subscriptions","organizations_url":"https://api.github.com/users/gyuho/orgs","repos_url":"https://api.github.com/users/gyuho/repos","events_url":"https://api.github.com/users/gyuho/events{/privacy}","received_events_url":"https://api.github.com/users/gyuho/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gyuho/etcd","description":"A distributed consistent key-value store for shared configuration and service discovery","fork":true,"url":"https://api.github.com/repos/gyuho/etcd","forks_url":"https://api.github.com/repos/gyuho/etcd/forks","keys_url":"https://api.github.com/repos/gyuho/etcd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gyuho/etcd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gyuho/etcd/teams","hooks_url":"https://api.github.com/repos/gyuho/etcd/hooks","issue_events_url":"https://api.github.com/repos/gyuho/etcd/issues/events{/number}","events_url":"https://api.github.com/repos/gyuho/etcd/events","assignees_url":"https://api.github.com/repos/gyuho/etcd/assignees{/user}","branches_url":"https://api.github.com/repos/gyuho/etcd/branches{/branch}","tags_url":"https://api.github.com/repos/gyuho/etcd/tags","blobs_url":"https://api.github.com/repos/gyuho/etcd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gyuho/etcd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gyuho/etcd/git/refs{/sha}","trees_url":"https://api.github.com/repos/gyuho/etcd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gyuho/etcd/statuses/{sha}","languages_url":"https://api.github.com/repos/gyuho/etcd/languages","stargazers_url":"https://api.github.com/repos/gyuho/etcd/stargazers","contributors_url":"https://api.github.com/repos/gyuho/etcd/contributors","subscribers_url":"https://api.github.com/repos/gyuho/etcd/subscribers","subscription_url":"https://api.github.com/repos/gyuho/etcd/subscription","commits_url":"https://api.github.com/repos/gyuho/etcd/commits{/sha}","git_commits_url":"https://api.github.com/repos/gyuho/etcd/git/commits{/sha}","comments_url":"https://api.github.com/repos/gyuho/etcd/comments{/number}","issue_comment_url":"https://api.github.com/repos/gyuho/etcd/issues/comments{/number}","contents_url":"https://api.github.com/repos/gyuho/etcd/contents/{+path}","compare_url":"https://api.github.com/repos/gyuho/etcd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gyuho/etcd/merges","archive_url":"https://api.github.com/repos/gyuho/etcd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gyuho/etcd/downloads","issues_url":"https://api.github.com/repos/gyuho/etcd/issues{/number}","pulls_url":"https://api.github.com/repos/gyuho/etcd/pulls{/number}","milestones_url":"https://api.github.com/repos/gyuho/etcd/milestones{/number}","notifications_url":"https://api.github.com/repos/gyuho/etcd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gyuho/etcd/labels{/name}","releases_url":"https://api.github.com/repos/gyuho/etcd/releases{/id}","created_at":"2015-09-23T06:15:42Z","updated_at":"2015-09-23T06:15:45Z","pushed_at":"2015-11-24T07:28:54Z","git_url":"git://github.com/gyuho/etcd.git","ssh_url":"git@github.com:gyuho/etcd.git","clone_url":"https://github.com/gyuho/etcd.git","svn_url":"https://github.com/gyuho/etcd","homepage":"","size":19055,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"coreos:master","ref":"master","sha":"31ac6ad44845f1defbbd315f3b353a3f5d32d5b6","user":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"repo":{"id":11225014,"name":"etcd","full_name":"coreos/etcd","owner":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coreos/etcd","description":"Distributed reliable key-value store for the most critical data of a distributed system","fork":false,"url":"https://api.github.com/repos/coreos/etcd","forks_url":"https://api.github.com/repos/coreos/etcd/forks","keys_url":"https://api.github.com/repos/coreos/etcd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coreos/etcd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coreos/etcd/teams","hooks_url":"https://api.github.com/repos/coreos/etcd/hooks","issue_events_url":"https://api.github.com/repos/coreos/etcd/issues/events{/number}","events_url":"https://api.github.com/repos/coreos/etcd/events","assignees_url":"https://api.github.com/repos/coreos/etcd/assignees{/user}","branches_url":"https://api.github.com/repos/coreos/etcd/branches{/branch}","tags_url":"https://api.github.com/repos/coreos/etcd/tags","blobs_url":"https://api.github.com/repos/coreos/etcd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coreos/etcd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coreos/etcd/git/refs{/sha}","trees_url":"https://api.github.com/repos/coreos/etcd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coreos/etcd/statuses/{sha}","languages_url":"https://api.github.com/repos/coreos/etcd/languages","stargazers_url":"https://api.github.com/repos/coreos/etcd/stargazers","contributors_url":"https://api.github.com/repos/coreos/etcd/contributors","subscribers_url":"https://api.github.com/repos/coreos/etcd/subscribers","subscription_url":"https://api.github.com/repos/coreos/etcd/subscription","commits_url":"https://api.github.com/repos/coreos/etcd/commits{/sha}","git_commits_url":"https://api.github.com/repos/coreos/etcd/git/commits{/sha}","comments_url":"https://api.github.com/repos/coreos/etcd/comments{/number}","issue_comment_url":"https://api.github.com/repos/coreos/etcd/issues/comments{/number}","contents_url":"https://api.github.com/repos/coreos/etcd/contents/{+path}","compare_url":"https://api.github.com/repos/coreos/etcd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coreos/etcd/merges","archive_url":"https://api.github.com/repos/coreos/etcd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coreos/etcd/downloads","issues_url":"https://api.github.com/repos/coreos/etcd/issues{/number}","pulls_url":"https://api.github.com/repos/coreos/etcd/pulls{/number}","milestones_url":"https://api.github.com/repos/coreos/etcd/milestones{/number}","notifications_url":"https://api.github.com/repos/coreos/etcd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coreos/etcd/labels{/name}","releases_url":"https://api.github.com/repos/coreos/etcd/releases{/id}","created_at":"2013-07-06T21:57:21Z","updated_at":"2015-11-24T04:02:39Z","pushed_at":"2015-11-24T07:32:33Z","git_url":"git://github.com/coreos/etcd.git","ssh_url":"git@github.com:coreos/etcd.git","clone_url":"https://github.com/coreos/etcd.git","svn_url":"https://github.com/coreos/etcd","homepage":"https://coreos.com/etcd/docs/latest/","size":21064,"stargazers_count":8085,"watchers_count":8085,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1244,"mirror_url":null,"open_issues_count":154,"forks":1244,"open_issues":154,"watchers":8085,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd/pulls/3645"},"html":{"href":"https://github.com/coreos/etcd/pull/3645"},"issue":{"href":"https://api.github.com/repos/coreos/etcd/issues/3645"},"comments":{"href":"https://api.github.com/repos/coreos/etcd/issues/3645/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/etcd/pulls/3645/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/etcd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coreos/etcd/pulls/3645/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/etcd/statuses/c6ec210b0d777c765c9b63ef1256232544ed6ad5"}}}}