{"action":"created","comment":{"url":"https://api.github.com/repos/olalonde/follow-redirects/pulls/comments/58316906","id":58316906,"diff_hunk":"@@ -23,10 +23,25 @@ module.exports = function(_nativeProtocols) {\n   return publicApi;\n \n   function execute(options) {\n-    var clientRequest;\n     var fetchedUrls = [];\n-\n-    return (clientRequest = cb());\n+    var clientRequest = cb();\n+    var requestProxy = Object.create(clientRequest);\n+\n+    // separate the proxy's event handlers from the request's\n+    requestProxy._events = {};\n+    requestProxy._eventsCount = 0;\n+    if (options.userCallback) {\n+      requestProxy.on('response', options.userCallback);\n+    }\n+    // forward all request events on the proxy except `response`","path":"create.js","position":17,"original_position":17,"commit_id":"413089f5102eb273a3c9d3c81a152e80e85822ac","original_commit_id":"413089f5102eb273a3c9d3c81a152e80e85822ac","user":{"login":"RubenVerborgh","id":675313,"avatar_url":"https://avatars.githubusercontent.com/u/675313?v=3","gravatar_id":"","url":"https://api.github.com/users/RubenVerborgh","html_url":"https://github.com/RubenVerborgh","followers_url":"https://api.github.com/users/RubenVerborgh/followers","following_url":"https://api.github.com/users/RubenVerborgh/following{/other_user}","gists_url":"https://api.github.com/users/RubenVerborgh/gists{/gist_id}","starred_url":"https://api.github.com/users/RubenVerborgh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RubenVerborgh/subscriptions","organizations_url":"https://api.github.com/users/RubenVerborgh/orgs","repos_url":"https://api.github.com/users/RubenVerborgh/repos","events_url":"https://api.github.com/users/RubenVerborgh/events{/privacy}","received_events_url":"https://api.github.com/users/RubenVerborgh/received_events","type":"User","site_admin":false},"body":"I could have a look at `abort`, but that probably belongs to a different issue (where we'd discuss desired behavior etc.).","created_at":"2016-04-03T20:21:01Z","updated_at":"2016-04-03T20:21:01Z","html_url":"https://github.com/olalonde/follow-redirects/pull/31#discussion_r58316906","pull_request_url":"https://api.github.com/repos/olalonde/follow-redirects/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/olalonde/follow-redirects/pulls/comments/58316906"},"html":{"href":"https://github.com/olalonde/follow-redirects/pull/31#discussion_r58316906"},"pull_request":{"href":"https://api.github.com/repos/olalonde/follow-redirects/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/olalonde/follow-redirects/pulls/31","id":65077451,"html_url":"https://github.com/olalonde/follow-redirects/pull/31","diff_url":"https://github.com/olalonde/follow-redirects/pull/31.diff","patch_url":"https://github.com/olalonde/follow-redirects/pull/31.patch","issue_url":"https://api.github.com/repos/olalonde/follow-redirects/issues/31","number":31,"state":"open","locked":false,"title":"Restore the response event.","user":{"login":"RubenVerborgh","id":675313,"avatar_url":"https://avatars.githubusercontent.com/u/675313?v=3","gravatar_id":"","url":"https://api.github.com/users/RubenVerborgh","html_url":"https://github.com/RubenVerborgh","followers_url":"https://api.github.com/users/RubenVerborgh/followers","following_url":"https://api.github.com/users/RubenVerborgh/following{/other_user}","gists_url":"https://api.github.com/users/RubenVerborgh/gists{/gist_id}","starred_url":"https://api.github.com/users/RubenVerborgh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RubenVerborgh/subscriptions","organizations_url":"https://api.github.com/users/RubenVerborgh/orgs","repos_url":"https://api.github.com/users/RubenVerborgh/repos","events_url":"https://api.github.com/users/RubenVerborgh/events{/privacy}","received_events_url":"https://api.github.com/users/RubenVerborgh/received_events","type":"User","site_admin":false},"body":"In #30, I remarked that the `response` event—and hence, the passed callback—do not behave as in the original Node.js API.\r\n\r\nThis pull request fixes that, by returning a proxied request rather than the original request. They proxy and the request are identical, except for event handling: the proxy only fires the `response` event when the final redirected response arrives, whereas the (now internal) `response` event of the request fires as soon as the first (non-redirected) response arrives.","created_at":"2016-04-03T19:17:01Z","updated_at":"2016-04-03T20:21:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"582770e0f88aef7423b3f04793145bf2ebab7d8e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/olalonde/follow-redirects/pulls/31/commits","review_comments_url":"https://api.github.com/repos/olalonde/follow-redirects/pulls/31/comments","review_comment_url":"https://api.github.com/repos/olalonde/follow-redirects/pulls/comments{/number}","comments_url":"https://api.github.com/repos/olalonde/follow-redirects/issues/31/comments","statuses_url":"https://api.github.com/repos/olalonde/follow-redirects/statuses/413089f5102eb273a3c9d3c81a152e80e85822ac","head":{"label":"RubenVerborgh:fix-response-event","ref":"fix-response-event","sha":"413089f5102eb273a3c9d3c81a152e80e85822ac","user":{"login":"RubenVerborgh","id":675313,"avatar_url":"https://avatars.githubusercontent.com/u/675313?v=3","gravatar_id":"","url":"https://api.github.com/users/RubenVerborgh","html_url":"https://github.com/RubenVerborgh","followers_url":"https://api.github.com/users/RubenVerborgh/followers","following_url":"https://api.github.com/users/RubenVerborgh/following{/other_user}","gists_url":"https://api.github.com/users/RubenVerborgh/gists{/gist_id}","starred_url":"https://api.github.com/users/RubenVerborgh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RubenVerborgh/subscriptions","organizations_url":"https://api.github.com/users/RubenVerborgh/orgs","repos_url":"https://api.github.com/users/RubenVerborgh/repos","events_url":"https://api.github.com/users/RubenVerborgh/events{/privacy}","received_events_url":"https://api.github.com/users/RubenVerborgh/received_events","type":"User","site_admin":false},"repo":{"id":55363926,"name":"follow-redirects","full_name":"RubenVerborgh/follow-redirects","owner":{"login":"RubenVerborgh","id":675313,"avatar_url":"https://avatars.githubusercontent.com/u/675313?v=3","gravatar_id":"","url":"https://api.github.com/users/RubenVerborgh","html_url":"https://github.com/RubenVerborgh","followers_url":"https://api.github.com/users/RubenVerborgh/followers","following_url":"https://api.github.com/users/RubenVerborgh/following{/other_user}","gists_url":"https://api.github.com/users/RubenVerborgh/gists{/gist_id}","starred_url":"https://api.github.com/users/RubenVerborgh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RubenVerborgh/subscriptions","organizations_url":"https://api.github.com/users/RubenVerborgh/orgs","repos_url":"https://api.github.com/users/RubenVerborgh/repos","events_url":"https://api.github.com/users/RubenVerborgh/events{/privacy}","received_events_url":"https://api.github.com/users/RubenVerborgh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RubenVerborgh/follow-redirects","description":"Drop in replacement for the HTTP and HTTPS modules to automatically follow redirects","fork":true,"url":"https://api.github.com/repos/RubenVerborgh/follow-redirects","forks_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/forks","keys_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/teams","hooks_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/hooks","issue_events_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/issues/events{/number}","events_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/events","assignees_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/assignees{/user}","branches_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/branches{/branch}","tags_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/tags","blobs_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/git/refs{/sha}","trees_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/statuses/{sha}","languages_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/languages","stargazers_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/stargazers","contributors_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/contributors","subscribers_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/subscribers","subscription_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/subscription","commits_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/commits{/sha}","git_commits_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/git/commits{/sha}","comments_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/comments{/number}","issue_comment_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/issues/comments{/number}","contents_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/contents/{+path}","compare_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/merges","archive_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/downloads","issues_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/issues{/number}","pulls_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/pulls{/number}","milestones_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/milestones{/number}","notifications_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/labels{/name}","releases_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/releases{/id}","deployments_url":"https://api.github.com/repos/RubenVerborgh/follow-redirects/deployments","created_at":"2016-04-03T19:11:34Z","updated_at":"2016-04-03T19:11:35Z","pushed_at":"2016-04-03T19:33:49Z","git_url":"git://github.com/RubenVerborgh/follow-redirects.git","ssh_url":"git@github.com:RubenVerborgh/follow-redirects.git","clone_url":"https://github.com/RubenVerborgh/follow-redirects.git","svn_url":"https://github.com/RubenVerborgh/follow-redirects","homepage":"http://syskall.com/how-to-follow-http-redirects-in-node-dot-js/","size":115,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"olalonde:master","ref":"master","sha":"0243ba264bc4db4e49d5fc6d1e70e14af72857fa","user":{"login":"olalonde","id":416585,"avatar_url":"https://avatars.githubusercontent.com/u/416585?v=3","gravatar_id":"","url":"https://api.github.com/users/olalonde","html_url":"https://github.com/olalonde","followers_url":"https://api.github.com/users/olalonde/followers","following_url":"https://api.github.com/users/olalonde/following{/other_user}","gists_url":"https://api.github.com/users/olalonde/gists{/gist_id}","starred_url":"https://api.github.com/users/olalonde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olalonde/subscriptions","organizations_url":"https://api.github.com/users/olalonde/orgs","repos_url":"https://api.github.com/users/olalonde/repos","events_url":"https://api.github.com/users/olalonde/events{/privacy}","received_events_url":"https://api.github.com/users/olalonde/received_events","type":"User","site_admin":false},"repo":{"id":6697086,"name":"follow-redirects","full_name":"olalonde/follow-redirects","owner":{"login":"olalonde","id":416585,"avatar_url":"https://avatars.githubusercontent.com/u/416585?v=3","gravatar_id":"","url":"https://api.github.com/users/olalonde","html_url":"https://github.com/olalonde","followers_url":"https://api.github.com/users/olalonde/followers","following_url":"https://api.github.com/users/olalonde/following{/other_user}","gists_url":"https://api.github.com/users/olalonde/gists{/gist_id}","starred_url":"https://api.github.com/users/olalonde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olalonde/subscriptions","organizations_url":"https://api.github.com/users/olalonde/orgs","repos_url":"https://api.github.com/users/olalonde/repos","events_url":"https://api.github.com/users/olalonde/events{/privacy}","received_events_url":"https://api.github.com/users/olalonde/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/olalonde/follow-redirects","description":"Drop in replacement for the HTTP and HTTPS modules to automatically follow redirects","fork":false,"url":"https://api.github.com/repos/olalonde/follow-redirects","forks_url":"https://api.github.com/repos/olalonde/follow-redirects/forks","keys_url":"https://api.github.com/repos/olalonde/follow-redirects/keys{/key_id}","collaborators_url":"https://api.github.com/repos/olalonde/follow-redirects/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/olalonde/follow-redirects/teams","hooks_url":"https://api.github.com/repos/olalonde/follow-redirects/hooks","issue_events_url":"https://api.github.com/repos/olalonde/follow-redirects/issues/events{/number}","events_url":"https://api.github.com/repos/olalonde/follow-redirects/events","assignees_url":"https://api.github.com/repos/olalonde/follow-redirects/assignees{/user}","branches_url":"https://api.github.com/repos/olalonde/follow-redirects/branches{/branch}","tags_url":"https://api.github.com/repos/olalonde/follow-redirects/tags","blobs_url":"https://api.github.com/repos/olalonde/follow-redirects/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/olalonde/follow-redirects/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/olalonde/follow-redirects/git/refs{/sha}","trees_url":"https://api.github.com/repos/olalonde/follow-redirects/git/trees{/sha}","statuses_url":"https://api.github.com/repos/olalonde/follow-redirects/statuses/{sha}","languages_url":"https://api.github.com/repos/olalonde/follow-redirects/languages","stargazers_url":"https://api.github.com/repos/olalonde/follow-redirects/stargazers","contributors_url":"https://api.github.com/repos/olalonde/follow-redirects/contributors","subscribers_url":"https://api.github.com/repos/olalonde/follow-redirects/subscribers","subscription_url":"https://api.github.com/repos/olalonde/follow-redirects/subscription","commits_url":"https://api.github.com/repos/olalonde/follow-redirects/commits{/sha}","git_commits_url":"https://api.github.com/repos/olalonde/follow-redirects/git/commits{/sha}","comments_url":"https://api.github.com/repos/olalonde/follow-redirects/comments{/number}","issue_comment_url":"https://api.github.com/repos/olalonde/follow-redirects/issues/comments{/number}","contents_url":"https://api.github.com/repos/olalonde/follow-redirects/contents/{+path}","compare_url":"https://api.github.com/repos/olalonde/follow-redirects/compare/{base}...{head}","merges_url":"https://api.github.com/repos/olalonde/follow-redirects/merges","archive_url":"https://api.github.com/repos/olalonde/follow-redirects/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/olalonde/follow-redirects/downloads","issues_url":"https://api.github.com/repos/olalonde/follow-redirects/issues{/number}","pulls_url":"https://api.github.com/repos/olalonde/follow-redirects/pulls{/number}","milestones_url":"https://api.github.com/repos/olalonde/follow-redirects/milestones{/number}","notifications_url":"https://api.github.com/repos/olalonde/follow-redirects/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/olalonde/follow-redirects/labels{/name}","releases_url":"https://api.github.com/repos/olalonde/follow-redirects/releases{/id}","deployments_url":"https://api.github.com/repos/olalonde/follow-redirects/deployments","created_at":"2012-11-15T00:01:16Z","updated_at":"2016-03-29T00:02:51Z","pushed_at":"2016-04-03T19:33:50Z","git_url":"git://github.com/olalonde/follow-redirects.git","ssh_url":"git@github.com:olalonde/follow-redirects.git","clone_url":"https://github.com/olalonde/follow-redirects.git","svn_url":"https://github.com/olalonde/follow-redirects","homepage":"http://syskall.com/how-to-follow-http-redirects-in-node-dot-js/","size":331,"stargazers_count":74,"watchers_count":74,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":11,"forks":18,"open_issues":11,"watchers":74,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/olalonde/follow-redirects/pulls/31"},"html":{"href":"https://github.com/olalonde/follow-redirects/pull/31"},"issue":{"href":"https://api.github.com/repos/olalonde/follow-redirects/issues/31"},"comments":{"href":"https://api.github.com/repos/olalonde/follow-redirects/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/olalonde/follow-redirects/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/olalonde/follow-redirects/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/olalonde/follow-redirects/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/olalonde/follow-redirects/statuses/413089f5102eb273a3c9d3c81a152e80e85822ac"}}}}