{"action":"opened","number":253,"pull_request":{"url":"https://api.github.com/repos/eventlet/eventlet/pulls/253","id":47252693,"html_url":"https://github.com/eventlet/eventlet/pull/253","diff_url":"https://github.com/eventlet/eventlet/pull/253.diff","patch_url":"https://github.com/eventlet/eventlet/pull/253.patch","issue_url":"https://api.github.com/repos/eventlet/eventlet/issues/253","number":253,"state":"open","locked":false,"title":"Add on_open option in WebSocketWSGI","user":{"login":"fukuchidaisuke","id":6110152,"avatar_url":"https://avatars.githubusercontent.com/u/6110152?v=3","gravatar_id":"","url":"https://api.github.com/users/fukuchidaisuke","html_url":"https://github.com/fukuchidaisuke","followers_url":"https://api.github.com/users/fukuchidaisuke/followers","following_url":"https://api.github.com/users/fukuchidaisuke/following{/other_user}","gists_url":"https://api.github.com/users/fukuchidaisuke/gists{/gist_id}","starred_url":"https://api.github.com/users/fukuchidaisuke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fukuchidaisuke/subscriptions","organizations_url":"https://api.github.com/users/fukuchidaisuke/orgs","repos_url":"https://api.github.com/users/fukuchidaisuke/repos","events_url":"https://api.github.com/users/fukuchidaisuke/events{/privacy}","received_events_url":"https://api.github.com/users/fukuchidaisuke/received_events","type":"User","site_admin":false},"body":"This pull request adds flexibility on accepting websocket connections as follows.\r\n\r\n```Python\r\nimport base64\r\nimport eventlet\r\nfrom eventlet import wsgi, websocket\r\nimport six\r\nimport time\r\n\r\n\r\ndef handle(ws):\r\n    while True:\r\n        message = ws.wait()\r\n        if message is None:\r\n            break\r\n        print(\"received {0}\".format(message))\r\n        ws.send(message)\r\n\r\n\r\ndef on_open(environ):\r\n    if \"HTTP_COOKIE\" in environ:\r\n        cookie = six.moves.http_cookies.SimpleCookie()\r\n        cookie.load(environ[\"HTTP_COOKIE\"])\r\n        if (\"SID\" in cookie) and cookie[\"SID\"].value == \"validSession\":\r\n            return []\r\n\r\n    print(\"not authenticated\")\r\n\r\n    if \"QUERY_STRING\" not in environ:\r\n        raise websocket.BadRequest(status=\"403 Forbidden\")\r\n\r\n    queries = six.moves.urllib.parse.parse_qs(environ[\"QUERY_STRING\"])\r\n    if \"authorization_basic\" not in queries:\r\n        raise websocket.BadRequest(status=\"403 Forbidden\")\r\n\r\n    if queries[\"authorization_basic\"][0] != base64.b64encode(\"username:password\".encode()).decode():\r\n        raise websocket.BadRequest(status=\"403 Forbidden\")\r\n\r\n    expires = time.strftime(\"%a, %d-%b-%Y %T GMT\", time.gmtime(time.time() + 3600))\r\n    return [(\"Set-Cookie\", \"SID=validSession; Path=/; Expires={0}\".format(expires))]\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    wsgi.server(eventlet.listen((\"\", 8080)), websocket.WebSocketWSGI(handle, on_open=on_open))\r\n```\r\n","created_at":"2015-10-09T09:48:32Z","updated_at":"2015-10-09T09:48:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/eventlet/eventlet/pulls/253/commits","review_comments_url":"https://api.github.com/repos/eventlet/eventlet/pulls/253/comments","review_comment_url":"https://api.github.com/repos/eventlet/eventlet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/eventlet/eventlet/issues/253/comments","statuses_url":"https://api.github.com/repos/eventlet/eventlet/statuses/c1a6c90f523b9e7c620bc9252e48189cf9099786","head":{"label":"fukuchidaisuke:ws-on_open","ref":"ws-on_open","sha":"c1a6c90f523b9e7c620bc9252e48189cf9099786","user":{"login":"fukuchidaisuke","id":6110152,"avatar_url":"https://avatars.githubusercontent.com/u/6110152?v=3","gravatar_id":"","url":"https://api.github.com/users/fukuchidaisuke","html_url":"https://github.com/fukuchidaisuke","followers_url":"https://api.github.com/users/fukuchidaisuke/followers","following_url":"https://api.github.com/users/fukuchidaisuke/following{/other_user}","gists_url":"https://api.github.com/users/fukuchidaisuke/gists{/gist_id}","starred_url":"https://api.github.com/users/fukuchidaisuke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fukuchidaisuke/subscriptions","organizations_url":"https://api.github.com/users/fukuchidaisuke/orgs","repos_url":"https://api.github.com/users/fukuchidaisuke/repos","events_url":"https://api.github.com/users/fukuchidaisuke/events{/privacy}","received_events_url":"https://api.github.com/users/fukuchidaisuke/received_events","type":"User","site_admin":false},"repo":{"id":42506691,"name":"eventlet","full_name":"fukuchidaisuke/eventlet","owner":{"login":"fukuchidaisuke","id":6110152,"avatar_url":"https://avatars.githubusercontent.com/u/6110152?v=3","gravatar_id":"","url":"https://api.github.com/users/fukuchidaisuke","html_url":"https://github.com/fukuchidaisuke","followers_url":"https://api.github.com/users/fukuchidaisuke/followers","following_url":"https://api.github.com/users/fukuchidaisuke/following{/other_user}","gists_url":"https://api.github.com/users/fukuchidaisuke/gists{/gist_id}","starred_url":"https://api.github.com/users/fukuchidaisuke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fukuchidaisuke/subscriptions","organizations_url":"https://api.github.com/users/fukuchidaisuke/orgs","repos_url":"https://api.github.com/users/fukuchidaisuke/repos","events_url":"https://api.github.com/users/fukuchidaisuke/events{/privacy}","received_events_url":"https://api.github.com/users/fukuchidaisuke/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fukuchidaisuke/eventlet","description":"Concurrent networking library for Python (official mirror)","fork":true,"url":"https://api.github.com/repos/fukuchidaisuke/eventlet","forks_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/forks","keys_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/teams","hooks_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/hooks","issue_events_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/issues/events{/number}","events_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/events","assignees_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/assignees{/user}","branches_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/branches{/branch}","tags_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/tags","blobs_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/git/refs{/sha}","trees_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/statuses/{sha}","languages_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/languages","stargazers_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/stargazers","contributors_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/contributors","subscribers_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/subscribers","subscription_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/subscription","commits_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/commits{/sha}","git_commits_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/git/commits{/sha}","comments_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/comments{/number}","issue_comment_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/issues/comments{/number}","contents_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/contents/{+path}","compare_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/merges","archive_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/downloads","issues_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/issues{/number}","pulls_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/pulls{/number}","milestones_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/milestones{/number}","notifications_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/labels{/name}","releases_url":"https://api.github.com/repos/fukuchidaisuke/eventlet/releases{/id}","created_at":"2015-09-15T08:57:27Z","updated_at":"2015-09-15T08:57:27Z","pushed_at":"2015-10-09T09:00:40Z","git_url":"git://github.com/fukuchidaisuke/eventlet.git","ssh_url":"git@github.com:fukuchidaisuke/eventlet.git","clone_url":"https://github.com/fukuchidaisuke/eventlet.git","svn_url":"https://github.com/fukuchidaisuke/eventlet","homepage":"eventlet.net","size":7364,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"eventlet:master","ref":"master","sha":"5a4a7ead2435025e2c727c902d7e985be0204417","user":{"login":"eventlet","id":3017635,"avatar_url":"https://avatars.githubusercontent.com/u/3017635?v=3","gravatar_id":"","url":"https://api.github.com/users/eventlet","html_url":"https://github.com/eventlet","followers_url":"https://api.github.com/users/eventlet/followers","following_url":"https://api.github.com/users/eventlet/following{/other_user}","gists_url":"https://api.github.com/users/eventlet/gists{/gist_id}","starred_url":"https://api.github.com/users/eventlet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eventlet/subscriptions","organizations_url":"https://api.github.com/users/eventlet/orgs","repos_url":"https://api.github.com/users/eventlet/repos","events_url":"https://api.github.com/users/eventlet/events{/privacy}","received_events_url":"https://api.github.com/users/eventlet/received_events","type":"Organization","site_admin":false},"repo":{"id":7115259,"name":"eventlet","full_name":"eventlet/eventlet","owner":{"login":"eventlet","id":3017635,"avatar_url":"https://avatars.githubusercontent.com/u/3017635?v=3","gravatar_id":"","url":"https://api.github.com/users/eventlet","html_url":"https://github.com/eventlet","followers_url":"https://api.github.com/users/eventlet/followers","following_url":"https://api.github.com/users/eventlet/following{/other_user}","gists_url":"https://api.github.com/users/eventlet/gists{/gist_id}","starred_url":"https://api.github.com/users/eventlet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eventlet/subscriptions","organizations_url":"https://api.github.com/users/eventlet/orgs","repos_url":"https://api.github.com/users/eventlet/repos","events_url":"https://api.github.com/users/eventlet/events{/privacy}","received_events_url":"https://api.github.com/users/eventlet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/eventlet/eventlet","description":"Concurrent networking library for Python (official mirror)","fork":false,"url":"https://api.github.com/repos/eventlet/eventlet","forks_url":"https://api.github.com/repos/eventlet/eventlet/forks","keys_url":"https://api.github.com/repos/eventlet/eventlet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eventlet/eventlet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eventlet/eventlet/teams","hooks_url":"https://api.github.com/repos/eventlet/eventlet/hooks","issue_events_url":"https://api.github.com/repos/eventlet/eventlet/issues/events{/number}","events_url":"https://api.github.com/repos/eventlet/eventlet/events","assignees_url":"https://api.github.com/repos/eventlet/eventlet/assignees{/user}","branches_url":"https://api.github.com/repos/eventlet/eventlet/branches{/branch}","tags_url":"https://api.github.com/repos/eventlet/eventlet/tags","blobs_url":"https://api.github.com/repos/eventlet/eventlet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eventlet/eventlet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eventlet/eventlet/git/refs{/sha}","trees_url":"https://api.github.com/repos/eventlet/eventlet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eventlet/eventlet/statuses/{sha}","languages_url":"https://api.github.com/repos/eventlet/eventlet/languages","stargazers_url":"https://api.github.com/repos/eventlet/eventlet/stargazers","contributors_url":"https://api.github.com/repos/eventlet/eventlet/contributors","subscribers_url":"https://api.github.com/repos/eventlet/eventlet/subscribers","subscription_url":"https://api.github.com/repos/eventlet/eventlet/subscription","commits_url":"https://api.github.com/repos/eventlet/eventlet/commits{/sha}","git_commits_url":"https://api.github.com/repos/eventlet/eventlet/git/commits{/sha}","comments_url":"https://api.github.com/repos/eventlet/eventlet/comments{/number}","issue_comment_url":"https://api.github.com/repos/eventlet/eventlet/issues/comments{/number}","contents_url":"https://api.github.com/repos/eventlet/eventlet/contents/{+path}","compare_url":"https://api.github.com/repos/eventlet/eventlet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eventlet/eventlet/merges","archive_url":"https://api.github.com/repos/eventlet/eventlet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eventlet/eventlet/downloads","issues_url":"https://api.github.com/repos/eventlet/eventlet/issues{/number}","pulls_url":"https://api.github.com/repos/eventlet/eventlet/pulls{/number}","milestones_url":"https://api.github.com/repos/eventlet/eventlet/milestones{/number}","notifications_url":"https://api.github.com/repos/eventlet/eventlet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eventlet/eventlet/labels{/name}","releases_url":"https://api.github.com/repos/eventlet/eventlet/releases{/id}","created_at":"2012-12-11T16:33:20Z","updated_at":"2015-10-07T15:21:08Z","pushed_at":"2015-10-09T01:10:02Z","git_url":"git://github.com/eventlet/eventlet.git","ssh_url":"git@github.com:eventlet/eventlet.git","clone_url":"https://github.com/eventlet/eventlet.git","svn_url":"https://github.com/eventlet/eventlet","homepage":"eventlet.net","size":9921,"stargazers_count":280,"watchers_count":280,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":97,"mirror_url":null,"open_issues_count":76,"forks":97,"open_issues":76,"watchers":280,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/eventlet/eventlet/pulls/253"},"html":{"href":"https://github.com/eventlet/eventlet/pull/253"},"issue":{"href":"https://api.github.com/repos/eventlet/eventlet/issues/253"},"comments":{"href":"https://api.github.com/repos/eventlet/eventlet/issues/253/comments"},"review_comments":{"href":"https://api.github.com/repos/eventlet/eventlet/pulls/253/comments"},"review_comment":{"href":"https://api.github.com/repos/eventlet/eventlet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/eventlet/eventlet/pulls/253/commits"},"statuses":{"href":"https://api.github.com/repos/eventlet/eventlet/statuses/c1a6c90f523b9e7c620bc9252e48189cf9099786"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":19,"deletions":4,"changed_files":1}}