{"action":"created","comment":{"url":"https://api.github.com/repos/getlantern/http-proxy/pulls/comments/60084018","id":60084018,"diff_hunk":"@@ -42,77 +69,34 @@ func (s *Server) AddListenerWrappers(listenerGens ...listenerGenerator) {\n \t}\n }\n \n-func (s *Server) ServeHTTP(addr string, readyCb func(addr string)) error {\n+func (s *Server) ListenAndServeHTTP(addr string, readyCb func(addr string)) error {\n \tlistener, err := net.Listen(\"tcp\", addr)\n \tif err != nil {\n \t\treturn err\n \t}\n-\ts.Tls = false\n \tlog.Debugf(\"Listen http on %s\", addr)\n-\treturn s.doServe(listener, readyCb)\n+\treturn s.Serve(listener, readyCb)\n }\n \n-func (s *Server) ServeHTTPS(addr, keyfile, certfile string, readyCb func(addr string)) error {\n-\tlistener, err := listenTLS(addr, keyfile, certfile)\n+func (s *Server) ListenAndServeHTTPS(addr, keyfile, certfile string, readyCb func(addr string)) error {\n+\tlistener, err := tlsdefaults.Listen(addr, keyfile, certfile)\n \tif err != nil {\n \t\treturn err\n \t}\n-\ts.Tls = true\n \tlog.Debugf(\"Listen https on %s\", addr)\n-\treturn s.doServe(listener, readyCb)\n+\treturn s.Serve(listener, readyCb)\n }\n \n-func (s *Server) doServe(listener net.Listener, readyCb func(addr string)) error {\n-\tcb := NewConnBag()\n-\n-\tproxy := http.HandlerFunc(\n-\t\tfunc(w http.ResponseWriter, req *http.Request) {\n-\t\t\tc := cb.Withdraw(req.RemoteAddr)\n-\t\t\tcontext.Set(req, \"conn\", c)\n-\t\t\ts.handler.ServeHTTP(w, req)\n-\t\t\tcontext.Clear(req)\n-\t\t})\n-\n-\ts.httpServer = http.Server{Handler: proxy,\n-\t\tConnState: func(c net.Conn, state http.ConnState) {\n-\t\t\twconn, ok := c.(listeners.WrapConn)\n-\t\t\tif !ok {\n-\t\t\t\tpanic(\"Should be of type WrapConn\")\n-\t\t\t}\n-\n-\t\t\twconn.OnState(state)\n-\n-\t\t\tswitch state {\n-\t\t\tcase http.StateActive:\n-\t\t\t\tcb.Put(wconn)\n-\t\t\tcase http.StateClosed:\n-\t\t\t\t// When go server encounters abnormal request, it\n-\t\t\t\t// will transit to StateClosed directly without\n-\t\t\t\t// the handler being invoked, hence the connection\n-\t\t\t\t// will not be withdrawed. Purge it in such case.\n-\t\t\t\tcb.Purge(c.RemoteAddr().String())\n-\t\t\t}\n-\t\t},\n-\t\tErrorLog: log.AsStdLogger(),\n-\t}\n-\n-\tfirstListener := listeners.NewDefaultListener(listener)\n-\tfirstListenerPtr := &firstListener\n-\ts.listeners = []*net.Listener{firstListenerPtr}\n+func (s *Server) Serve(listener net.Listener, readyCb func(addr string)) error {\n+\tl := listeners.NewDefaultListener(listener)\n \n-\tfor _, li := range s.listenerGenerators {\n-\t\tnewlis := li(*firstListenerPtr)\n-\t\ts.listeners = append(s.listeners, &newlis)","path":"server/server.go","position":130,"original_position":130,"commit_id":"fcb64d3845e1daafc1317d2bcdad67c713d2da2c","original_commit_id":"fcb64d3845e1daafc1317d2bcdad67c713d2da2c","user":{"login":"uaalto","id":12701448,"avatar_url":"https://avatars.githubusercontent.com/u/12701448?v=3","gravatar_id":"","url":"https://api.github.com/users/uaalto","html_url":"https://github.com/uaalto","followers_url":"https://api.github.com/users/uaalto/followers","following_url":"https://api.github.com/users/uaalto/following{/other_user}","gists_url":"https://api.github.com/users/uaalto/gists{/gist_id}","starred_url":"https://api.github.com/users/uaalto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uaalto/subscriptions","organizations_url":"https://api.github.com/users/uaalto/orgs","repos_url":"https://api.github.com/users/uaalto/repos","events_url":"https://api.github.com/users/uaalto/events{/privacy}","received_events_url":"https://api.github.com/users/uaalto/received_events","type":"User","site_admin":false},"body":"Did you remove the listeners attribute because of a race condition or just because it wasn't being used at the moment?","created_at":"2016-04-18T15:54:50Z","updated_at":"2016-04-18T15:54:50Z","html_url":"https://github.com/getlantern/http-proxy/pull/77#discussion_r60084018","pull_request_url":"https://api.github.com/repos/getlantern/http-proxy/pulls/77","_links":{"self":{"href":"https://api.github.com/repos/getlantern/http-proxy/pulls/comments/60084018"},"html":{"href":"https://github.com/getlantern/http-proxy/pull/77#discussion_r60084018"},"pull_request":{"href":"https://api.github.com/repos/getlantern/http-proxy/pulls/77"}}},"pull_request":{"url":"https://api.github.com/repos/getlantern/http-proxy/pulls/77","id":63795926,"html_url":"https://github.com/getlantern/http-proxy/pull/77","diff_url":"https://github.com/getlantern/http-proxy/pull/77.diff","patch_url":"https://github.com/getlantern/http-proxy/pull/77.patch","issue_url":"https://api.github.com/repos/getlantern/http-proxy/issues/77","number":77,"state":"open","locked":false,"title":"Added ability to listen on multiple ports with multiple protocols","user":{"login":"oxtoacart","id":5000654,"avatar_url":"https://avatars.githubusercontent.com/u/5000654?v=3","gravatar_id":"","url":"https://api.github.com/users/oxtoacart","html_url":"https://github.com/oxtoacart","followers_url":"https://api.github.com/users/oxtoacart/followers","following_url":"https://api.github.com/users/oxtoacart/following{/other_user}","gists_url":"https://api.github.com/users/oxtoacart/gists{/gist_id}","starred_url":"https://api.github.com/users/oxtoacart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oxtoacart/subscriptions","organizations_url":"https://api.github.com/users/oxtoacart/orgs","repos_url":"https://api.github.com/users/oxtoacart/repos","events_url":"https://api.github.com/users/oxtoacart/events{/privacy}","received_events_url":"https://api.github.com/users/oxtoacart/received_events","type":"User","site_admin":false},"body":"This change allows http-proxy to serve multiple listeners.  It's needed for getlantern/lantern#3172.","created_at":"2016-03-22T21:26:35Z","updated_at":"2016-04-18T15:54:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1991fd07143776664b2bfa05cb0ba9c4d47e6d87","assignee":{"login":"uaalto","id":12701448,"avatar_url":"https://avatars.githubusercontent.com/u/12701448?v=3","gravatar_id":"","url":"https://api.github.com/users/uaalto","html_url":"https://github.com/uaalto","followers_url":"https://api.github.com/users/uaalto/followers","following_url":"https://api.github.com/users/uaalto/following{/other_user}","gists_url":"https://api.github.com/users/uaalto/gists{/gist_id}","starred_url":"https://api.github.com/users/uaalto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uaalto/subscriptions","organizations_url":"https://api.github.com/users/uaalto/orgs","repos_url":"https://api.github.com/users/uaalto/repos","events_url":"https://api.github.com/users/uaalto/events{/privacy}","received_events_url":"https://api.github.com/users/uaalto/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/getlantern/http-proxy/pulls/77/commits","review_comments_url":"https://api.github.com/repos/getlantern/http-proxy/pulls/77/comments","review_comment_url":"https://api.github.com/repos/getlantern/http-proxy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/getlantern/http-proxy/issues/77/comments","statuses_url":"https://api.github.com/repos/getlantern/http-proxy/statuses/fcb64d3845e1daafc1317d2bcdad67c713d2da2c","head":{"label":"getlantern:obfs4","ref":"obfs4","sha":"fcb64d3845e1daafc1317d2bcdad67c713d2da2c","user":{"login":"getlantern","id":624178,"avatar_url":"https://avatars.githubusercontent.com/u/624178?v=3","gravatar_id":"","url":"https://api.github.com/users/getlantern","html_url":"https://github.com/getlantern","followers_url":"https://api.github.com/users/getlantern/followers","following_url":"https://api.github.com/users/getlantern/following{/other_user}","gists_url":"https://api.github.com/users/getlantern/gists{/gist_id}","starred_url":"https://api.github.com/users/getlantern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getlantern/subscriptions","organizations_url":"https://api.github.com/users/getlantern/orgs","repos_url":"https://api.github.com/users/getlantern/repos","events_url":"https://api.github.com/users/getlantern/events{/privacy}","received_events_url":"https://api.github.com/users/getlantern/received_events","type":"Organization","site_admin":false},"repo":{"id":43355708,"name":"http-proxy","full_name":"getlantern/http-proxy","owner":{"login":"getlantern","id":624178,"avatar_url":"https://avatars.githubusercontent.com/u/624178?v=3","gravatar_id":"","url":"https://api.github.com/users/getlantern","html_url":"https://github.com/getlantern","followers_url":"https://api.github.com/users/getlantern/followers","following_url":"https://api.github.com/users/getlantern/following{/other_user}","gists_url":"https://api.github.com/users/getlantern/gists{/gist_id}","starred_url":"https://api.github.com/users/getlantern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getlantern/subscriptions","organizations_url":"https://api.github.com/users/getlantern/orgs","repos_url":"https://api.github.com/users/getlantern/repos","events_url":"https://api.github.com/users/getlantern/events{/privacy}","received_events_url":"https://api.github.com/users/getlantern/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getlantern/http-proxy","description":"HTTP Proxy with TLS support","fork":false,"url":"https://api.github.com/repos/getlantern/http-proxy","forks_url":"https://api.github.com/repos/getlantern/http-proxy/forks","keys_url":"https://api.github.com/repos/getlantern/http-proxy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getlantern/http-proxy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getlantern/http-proxy/teams","hooks_url":"https://api.github.com/repos/getlantern/http-proxy/hooks","issue_events_url":"https://api.github.com/repos/getlantern/http-proxy/issues/events{/number}","events_url":"https://api.github.com/repos/getlantern/http-proxy/events","assignees_url":"https://api.github.com/repos/getlantern/http-proxy/assignees{/user}","branches_url":"https://api.github.com/repos/getlantern/http-proxy/branches{/branch}","tags_url":"https://api.github.com/repos/getlantern/http-proxy/tags","blobs_url":"https://api.github.com/repos/getlantern/http-proxy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getlantern/http-proxy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getlantern/http-proxy/git/refs{/sha}","trees_url":"https://api.github.com/repos/getlantern/http-proxy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getlantern/http-proxy/statuses/{sha}","languages_url":"https://api.github.com/repos/getlantern/http-proxy/languages","stargazers_url":"https://api.github.com/repos/getlantern/http-proxy/stargazers","contributors_url":"https://api.github.com/repos/getlantern/http-proxy/contributors","subscribers_url":"https://api.github.com/repos/getlantern/http-proxy/subscribers","subscription_url":"https://api.github.com/repos/getlantern/http-proxy/subscription","commits_url":"https://api.github.com/repos/getlantern/http-proxy/commits{/sha}","git_commits_url":"https://api.github.com/repos/getlantern/http-proxy/git/commits{/sha}","comments_url":"https://api.github.com/repos/getlantern/http-proxy/comments{/number}","issue_comment_url":"https://api.github.com/repos/getlantern/http-proxy/issues/comments{/number}","contents_url":"https://api.github.com/repos/getlantern/http-proxy/contents/{+path}","compare_url":"https://api.github.com/repos/getlantern/http-proxy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getlantern/http-proxy/merges","archive_url":"https://api.github.com/repos/getlantern/http-proxy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getlantern/http-proxy/downloads","issues_url":"https://api.github.com/repos/getlantern/http-proxy/issues{/number}","pulls_url":"https://api.github.com/repos/getlantern/http-proxy/pulls{/number}","milestones_url":"https://api.github.com/repos/getlantern/http-proxy/milestones{/number}","notifications_url":"https://api.github.com/repos/getlantern/http-proxy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getlantern/http-proxy/labels{/name}","releases_url":"https://api.github.com/repos/getlantern/http-proxy/releases{/id}","deployments_url":"https://api.github.com/repos/getlantern/http-proxy/deployments","created_at":"2015-09-29T08:47:32Z","updated_at":"2016-04-14T15:12:26Z","pushed_at":"2016-04-13T20:24:53Z","git_url":"git://github.com/getlantern/http-proxy.git","ssh_url":"git@github.com:getlantern/http-proxy.git","clone_url":"https://github.com/getlantern/http-proxy.git","svn_url":"https://github.com/getlantern/http-proxy","homepage":"","size":5340,"stargazers_count":22,"watchers_count":22,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":19,"forks":7,"open_issues":19,"watchers":22,"default_branch":"master"}},"base":{"label":"getlantern:master","ref":"master","sha":"e5bead037a0f386ef66932ea0e72d5f4ada295bf","user":{"login":"getlantern","id":624178,"avatar_url":"https://avatars.githubusercontent.com/u/624178?v=3","gravatar_id":"","url":"https://api.github.com/users/getlantern","html_url":"https://github.com/getlantern","followers_url":"https://api.github.com/users/getlantern/followers","following_url":"https://api.github.com/users/getlantern/following{/other_user}","gists_url":"https://api.github.com/users/getlantern/gists{/gist_id}","starred_url":"https://api.github.com/users/getlantern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getlantern/subscriptions","organizations_url":"https://api.github.com/users/getlantern/orgs","repos_url":"https://api.github.com/users/getlantern/repos","events_url":"https://api.github.com/users/getlantern/events{/privacy}","received_events_url":"https://api.github.com/users/getlantern/received_events","type":"Organization","site_admin":false},"repo":{"id":43355708,"name":"http-proxy","full_name":"getlantern/http-proxy","owner":{"login":"getlantern","id":624178,"avatar_url":"https://avatars.githubusercontent.com/u/624178?v=3","gravatar_id":"","url":"https://api.github.com/users/getlantern","html_url":"https://github.com/getlantern","followers_url":"https://api.github.com/users/getlantern/followers","following_url":"https://api.github.com/users/getlantern/following{/other_user}","gists_url":"https://api.github.com/users/getlantern/gists{/gist_id}","starred_url":"https://api.github.com/users/getlantern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getlantern/subscriptions","organizations_url":"https://api.github.com/users/getlantern/orgs","repos_url":"https://api.github.com/users/getlantern/repos","events_url":"https://api.github.com/users/getlantern/events{/privacy}","received_events_url":"https://api.github.com/users/getlantern/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getlantern/http-proxy","description":"HTTP Proxy with TLS support","fork":false,"url":"https://api.github.com/repos/getlantern/http-proxy","forks_url":"https://api.github.com/repos/getlantern/http-proxy/forks","keys_url":"https://api.github.com/repos/getlantern/http-proxy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getlantern/http-proxy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getlantern/http-proxy/teams","hooks_url":"https://api.github.com/repos/getlantern/http-proxy/hooks","issue_events_url":"https://api.github.com/repos/getlantern/http-proxy/issues/events{/number}","events_url":"https://api.github.com/repos/getlantern/http-proxy/events","assignees_url":"https://api.github.com/repos/getlantern/http-proxy/assignees{/user}","branches_url":"https://api.github.com/repos/getlantern/http-proxy/branches{/branch}","tags_url":"https://api.github.com/repos/getlantern/http-proxy/tags","blobs_url":"https://api.github.com/repos/getlantern/http-proxy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getlantern/http-proxy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getlantern/http-proxy/git/refs{/sha}","trees_url":"https://api.github.com/repos/getlantern/http-proxy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getlantern/http-proxy/statuses/{sha}","languages_url":"https://api.github.com/repos/getlantern/http-proxy/languages","stargazers_url":"https://api.github.com/repos/getlantern/http-proxy/stargazers","contributors_url":"https://api.github.com/repos/getlantern/http-proxy/contributors","subscribers_url":"https://api.github.com/repos/getlantern/http-proxy/subscribers","subscription_url":"https://api.github.com/repos/getlantern/http-proxy/subscription","commits_url":"https://api.github.com/repos/getlantern/http-proxy/commits{/sha}","git_commits_url":"https://api.github.com/repos/getlantern/http-proxy/git/commits{/sha}","comments_url":"https://api.github.com/repos/getlantern/http-proxy/comments{/number}","issue_comment_url":"https://api.github.com/repos/getlantern/http-proxy/issues/comments{/number}","contents_url":"https://api.github.com/repos/getlantern/http-proxy/contents/{+path}","compare_url":"https://api.github.com/repos/getlantern/http-proxy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getlantern/http-proxy/merges","archive_url":"https://api.github.com/repos/getlantern/http-proxy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getlantern/http-proxy/downloads","issues_url":"https://api.github.com/repos/getlantern/http-proxy/issues{/number}","pulls_url":"https://api.github.com/repos/getlantern/http-proxy/pulls{/number}","milestones_url":"https://api.github.com/repos/getlantern/http-proxy/milestones{/number}","notifications_url":"https://api.github.com/repos/getlantern/http-proxy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getlantern/http-proxy/labels{/name}","releases_url":"https://api.github.com/repos/getlantern/http-proxy/releases{/id}","deployments_url":"https://api.github.com/repos/getlantern/http-proxy/deployments","created_at":"2015-09-29T08:47:32Z","updated_at":"2016-04-14T15:12:26Z","pushed_at":"2016-04-13T20:24:53Z","git_url":"git://github.com/getlantern/http-proxy.git","ssh_url":"git@github.com:getlantern/http-proxy.git","clone_url":"https://github.com/getlantern/http-proxy.git","svn_url":"https://github.com/getlantern/http-proxy","homepage":"","size":5340,"stargazers_count":22,"watchers_count":22,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":19,"forks":7,"open_issues":19,"watchers":22,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/getlantern/http-proxy/pulls/77"},"html":{"href":"https://github.com/getlantern/http-proxy/pull/77"},"issue":{"href":"https://api.github.com/repos/getlantern/http-proxy/issues/77"},"comments":{"href":"https://api.github.com/repos/getlantern/http-proxy/issues/77/comments"},"review_comments":{"href":"https://api.github.com/repos/getlantern/http-proxy/pulls/77/comments"},"review_comment":{"href":"https://api.github.com/repos/getlantern/http-proxy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/getlantern/http-proxy/pulls/77/commits"},"statuses":{"href":"https://api.github.com/repos/getlantern/http-proxy/statuses/fcb64d3845e1daafc1317d2bcdad67c713d2da2c"}}}}