{"action":"created","comment":{"url":"https://api.github.com/repos/lostisland/faraday/pulls/comments/76886400","id":76886400,"diff_hunk":"@@ -75,9 +75,45 @@ def create_request(env)\n       end\n \n       def perform_request(http, env)\n+        if env[:request].stream_response?\n+          size = 0\n+          never_yielded = true\n+          http_response = perform_request_with_wrapped_block(http, env) do |chunk|\n+            if chunk.size > 0 || size > 0\n+              never_yielded = false\n+              size += chunk.bytesize\n+              env[:request].on_data.call(chunk, size)\n+            end\n+          end\n+          env[:request].on_data.call(\"\", 0) if never_yielded\n+          # Net::HTTP returns something, but it's not meaningful according to the docs.\n+          http_response.body = nil\n+          http_response\n+        else\n+          http_response = perform_request_with_wrapped_block(http, env)\n+        end\n+      end\n+\n+      def perform_request_with_wrapped_block(http, env, &block)\n         if :get == env[:method] and !env[:body]\n           # prefer `get` to `request` because the former handles gzip (ruby 1.9)\n-          http.get env[:url].request_uri, env[:request_headers]\n+          request_via_get_method(http, env, &block)\n+        else\n+          request_via_request_method(http, env, &block)\n+        end\n+      end\n+\n+      def request_via_get_method(http, env, &block)\n+        http.get env[:url].request_uri, env[:request_headers], &block\n+      end\n+\n+      def request_via_request_method(http, env, &block)\n+        if block_given?\n+          http.request create_request(env) do |response|\n+            response.read_body do |chunk|","path":"lib/faraday/adapter/net_http.rb","position":40,"original_position":40,"commit_id":"60cdd853545a06a19fd9cd771bbace1196cea141","original_commit_id":"60cdd853545a06a19fd9cd771bbace1196cea141","user":{"login":"grosser","id":11367,"avatar_url":"https://avatars.githubusercontent.com/u/11367?v=3","gravatar_id":"","url":"https://api.github.com/users/grosser","html_url":"https://github.com/grosser","followers_url":"https://api.github.com/users/grosser/followers","following_url":"https://api.github.com/users/grosser/following{/other_user}","gists_url":"https://api.github.com/users/grosser/gists{/gist_id}","starred_url":"https://api.github.com/users/grosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grosser/subscriptions","organizations_url":"https://api.github.com/users/grosser/orgs","repos_url":"https://api.github.com/users/grosser/repos","events_url":"https://api.github.com/users/grosser/events{/privacy}","received_events_url":"https://api.github.com/users/grosser/received_events","type":"User","site_admin":false},"body":"can simplify to `response.read_body(&block)`","created_at":"2016-08-30T21:50:25Z","updated_at":"2016-08-30T21:50:25Z","html_url":"https://github.com/lostisland/faraday/pull/604#discussion_r76886400","pull_request_url":"https://api.github.com/repos/lostisland/faraday/pulls/604","_links":{"self":{"href":"https://api.github.com/repos/lostisland/faraday/pulls/comments/76886400"},"html":{"href":"https://github.com/lostisland/faraday/pull/604#discussion_r76886400"},"pull_request":{"href":"https://api.github.com/repos/lostisland/faraday/pulls/604"}}},"pull_request":{"url":"https://api.github.com/repos/lostisland/faraday/pulls/604","id":83352587,"html_url":"https://github.com/lostisland/faraday/pull/604","diff_url":"https://github.com/lostisland/faraday/pull/604.diff","patch_url":"https://github.com/lostisland/faraday/pull/604.patch","issue_url":"https://api.github.com/repos/lostisland/faraday/issues/604","number":604,"state":"open","locked":false,"title":"Streaming requests for Net::HTTP","user":{"login":"nightscape","id":35170,"avatar_url":"https://avatars.githubusercontent.com/u/35170?v=3","gravatar_id":"","url":"https://api.github.com/users/nightscape","html_url":"https://github.com/nightscape","followers_url":"https://api.github.com/users/nightscape/followers","following_url":"https://api.github.com/users/nightscape/following{/other_user}","gists_url":"https://api.github.com/users/nightscape/gists{/gist_id}","starred_url":"https://api.github.com/users/nightscape/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nightscape/subscriptions","organizations_url":"https://api.github.com/users/nightscape/orgs","repos_url":"https://api.github.com/users/nightscape/repos","events_url":"https://api.github.com/users/nightscape/events{/privacy}","received_events_url":"https://api.github.com/users/nightscape/received_events","type":"User","site_admin":false},"body":"This PR is a rebased version of https://github.com/lostisland/faraday/pull/461 and https://github.com/lostisland/faraday/pull/522 including an additional test and fix for empty initial chunks mentioned by @grosser in https://github.com/lostisland/faraday/pull/461#issuecomment-139620539.\r\nTests are all green on my machine, so it would be great if someone (maybe @mislav or @iMacTia) could have a look at this :smiley:\r\nThe other two PRs can be closed in favor of this one.","created_at":"2016-08-30T21:40:34Z","updated_at":"2016-08-30T21:50:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6caac8e890e5b1c3c2aac66f9851233b1f68102b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/lostisland/faraday/pulls/604/commits","review_comments_url":"https://api.github.com/repos/lostisland/faraday/pulls/604/comments","review_comment_url":"https://api.github.com/repos/lostisland/faraday/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lostisland/faraday/issues/604/comments","statuses_url":"https://api.github.com/repos/lostisland/faraday/statuses/60cdd853545a06a19fd9cd771bbace1196cea141","head":{"label":"crealytics:streaming","ref":"streaming","sha":"60cdd853545a06a19fd9cd771bbace1196cea141","user":{"login":"crealytics","id":318741,"avatar_url":"https://avatars.githubusercontent.com/u/318741?v=3","gravatar_id":"","url":"https://api.github.com/users/crealytics","html_url":"https://github.com/crealytics","followers_url":"https://api.github.com/users/crealytics/followers","following_url":"https://api.github.com/users/crealytics/following{/other_user}","gists_url":"https://api.github.com/users/crealytics/gists{/gist_id}","starred_url":"https://api.github.com/users/crealytics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crealytics/subscriptions","organizations_url":"https://api.github.com/users/crealytics/orgs","repos_url":"https://api.github.com/users/crealytics/repos","events_url":"https://api.github.com/users/crealytics/events{/privacy}","received_events_url":"https://api.github.com/users/crealytics/received_events","type":"Organization","site_admin":false},"repo":{"id":66968596,"name":"faraday","full_name":"crealytics/faraday","owner":{"login":"crealytics","id":318741,"avatar_url":"https://avatars.githubusercontent.com/u/318741?v=3","gravatar_id":"","url":"https://api.github.com/users/crealytics","html_url":"https://github.com/crealytics","followers_url":"https://api.github.com/users/crealytics/followers","following_url":"https://api.github.com/users/crealytics/following{/other_user}","gists_url":"https://api.github.com/users/crealytics/gists{/gist_id}","starred_url":"https://api.github.com/users/crealytics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crealytics/subscriptions","organizations_url":"https://api.github.com/users/crealytics/orgs","repos_url":"https://api.github.com/users/crealytics/repos","events_url":"https://api.github.com/users/crealytics/events{/privacy}","received_events_url":"https://api.github.com/users/crealytics/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/crealytics/faraday","description":"Simple, but flexible HTTP client library, with support for multiple backends.","fork":true,"url":"https://api.github.com/repos/crealytics/faraday","forks_url":"https://api.github.com/repos/crealytics/faraday/forks","keys_url":"https://api.github.com/repos/crealytics/faraday/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crealytics/faraday/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crealytics/faraday/teams","hooks_url":"https://api.github.com/repos/crealytics/faraday/hooks","issue_events_url":"https://api.github.com/repos/crealytics/faraday/issues/events{/number}","events_url":"https://api.github.com/repos/crealytics/faraday/events","assignees_url":"https://api.github.com/repos/crealytics/faraday/assignees{/user}","branches_url":"https://api.github.com/repos/crealytics/faraday/branches{/branch}","tags_url":"https://api.github.com/repos/crealytics/faraday/tags","blobs_url":"https://api.github.com/repos/crealytics/faraday/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crealytics/faraday/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crealytics/faraday/git/refs{/sha}","trees_url":"https://api.github.com/repos/crealytics/faraday/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crealytics/faraday/statuses/{sha}","languages_url":"https://api.github.com/repos/crealytics/faraday/languages","stargazers_url":"https://api.github.com/repos/crealytics/faraday/stargazers","contributors_url":"https://api.github.com/repos/crealytics/faraday/contributors","subscribers_url":"https://api.github.com/repos/crealytics/faraday/subscribers","subscription_url":"https://api.github.com/repos/crealytics/faraday/subscription","commits_url":"https://api.github.com/repos/crealytics/faraday/commits{/sha}","git_commits_url":"https://api.github.com/repos/crealytics/faraday/git/commits{/sha}","comments_url":"https://api.github.com/repos/crealytics/faraday/comments{/number}","issue_comment_url":"https://api.github.com/repos/crealytics/faraday/issues/comments{/number}","contents_url":"https://api.github.com/repos/crealytics/faraday/contents/{+path}","compare_url":"https://api.github.com/repos/crealytics/faraday/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crealytics/faraday/merges","archive_url":"https://api.github.com/repos/crealytics/faraday/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crealytics/faraday/downloads","issues_url":"https://api.github.com/repos/crealytics/faraday/issues{/number}","pulls_url":"https://api.github.com/repos/crealytics/faraday/pulls{/number}","milestones_url":"https://api.github.com/repos/crealytics/faraday/milestones{/number}","notifications_url":"https://api.github.com/repos/crealytics/faraday/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crealytics/faraday/labels{/name}","releases_url":"https://api.github.com/repos/crealytics/faraday/releases{/id}","deployments_url":"https://api.github.com/repos/crealytics/faraday/deployments","created_at":"2016-08-30T18:52:04Z","updated_at":"2016-08-30T18:52:05Z","pushed_at":"2016-08-30T21:47:49Z","git_url":"git://github.com/crealytics/faraday.git","ssh_url":"git@github.com:crealytics/faraday.git","clone_url":"https://github.com/crealytics/faraday.git","svn_url":"https://github.com/crealytics/faraday","homepage":"","size":1205,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"lostisland:master","ref":"master","sha":"a712938071bb0997410b5de4a4f2517d30fc4d3d","user":{"login":"lostisland","id":2613464,"avatar_url":"https://avatars.githubusercontent.com/u/2613464?v=3","gravatar_id":"","url":"https://api.github.com/users/lostisland","html_url":"https://github.com/lostisland","followers_url":"https://api.github.com/users/lostisland/followers","following_url":"https://api.github.com/users/lostisland/following{/other_user}","gists_url":"https://api.github.com/users/lostisland/gists{/gist_id}","starred_url":"https://api.github.com/users/lostisland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lostisland/subscriptions","organizations_url":"https://api.github.com/users/lostisland/orgs","repos_url":"https://api.github.com/users/lostisland/repos","events_url":"https://api.github.com/users/lostisland/events{/privacy}","received_events_url":"https://api.github.com/users/lostisland/received_events","type":"Organization","site_admin":false},"repo":{"id":417389,"name":"faraday","full_name":"lostisland/faraday","owner":{"login":"lostisland","id":2613464,"avatar_url":"https://avatars.githubusercontent.com/u/2613464?v=3","gravatar_id":"","url":"https://api.github.com/users/lostisland","html_url":"https://github.com/lostisland","followers_url":"https://api.github.com/users/lostisland/followers","following_url":"https://api.github.com/users/lostisland/following{/other_user}","gists_url":"https://api.github.com/users/lostisland/gists{/gist_id}","starred_url":"https://api.github.com/users/lostisland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lostisland/subscriptions","organizations_url":"https://api.github.com/users/lostisland/orgs","repos_url":"https://api.github.com/users/lostisland/repos","events_url":"https://api.github.com/users/lostisland/events{/privacy}","received_events_url":"https://api.github.com/users/lostisland/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lostisland/faraday","description":"Simple, but flexible HTTP client library, with support for multiple backends.","fork":false,"url":"https://api.github.com/repos/lostisland/faraday","forks_url":"https://api.github.com/repos/lostisland/faraday/forks","keys_url":"https://api.github.com/repos/lostisland/faraday/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lostisland/faraday/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lostisland/faraday/teams","hooks_url":"https://api.github.com/repos/lostisland/faraday/hooks","issue_events_url":"https://api.github.com/repos/lostisland/faraday/issues/events{/number}","events_url":"https://api.github.com/repos/lostisland/faraday/events","assignees_url":"https://api.github.com/repos/lostisland/faraday/assignees{/user}","branches_url":"https://api.github.com/repos/lostisland/faraday/branches{/branch}","tags_url":"https://api.github.com/repos/lostisland/faraday/tags","blobs_url":"https://api.github.com/repos/lostisland/faraday/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lostisland/faraday/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lostisland/faraday/git/refs{/sha}","trees_url":"https://api.github.com/repos/lostisland/faraday/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lostisland/faraday/statuses/{sha}","languages_url":"https://api.github.com/repos/lostisland/faraday/languages","stargazers_url":"https://api.github.com/repos/lostisland/faraday/stargazers","contributors_url":"https://api.github.com/repos/lostisland/faraday/contributors","subscribers_url":"https://api.github.com/repos/lostisland/faraday/subscribers","subscription_url":"https://api.github.com/repos/lostisland/faraday/subscription","commits_url":"https://api.github.com/repos/lostisland/faraday/commits{/sha}","git_commits_url":"https://api.github.com/repos/lostisland/faraday/git/commits{/sha}","comments_url":"https://api.github.com/repos/lostisland/faraday/comments{/number}","issue_comment_url":"https://api.github.com/repos/lostisland/faraday/issues/comments{/number}","contents_url":"https://api.github.com/repos/lostisland/faraday/contents/{+path}","compare_url":"https://api.github.com/repos/lostisland/faraday/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lostisland/faraday/merges","archive_url":"https://api.github.com/repos/lostisland/faraday/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lostisland/faraday/downloads","issues_url":"https://api.github.com/repos/lostisland/faraday/issues{/number}","pulls_url":"https://api.github.com/repos/lostisland/faraday/pulls{/number}","milestones_url":"https://api.github.com/repos/lostisland/faraday/milestones{/number}","notifications_url":"https://api.github.com/repos/lostisland/faraday/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lostisland/faraday/labels{/name}","releases_url":"https://api.github.com/repos/lostisland/faraday/releases{/id}","deployments_url":"https://api.github.com/repos/lostisland/faraday/deployments","created_at":"2009-12-10T17:14:55Z","updated_at":"2016-08-30T21:19:41Z","pushed_at":"2016-08-30T21:47:49Z","git_url":"git://github.com/lostisland/faraday.git","ssh_url":"git@github.com:lostisland/faraday.git","clone_url":"https://github.com/lostisland/faraday.git","svn_url":"https://github.com/lostisland/faraday","homepage":"","size":2524,"stargazers_count":3224,"watchers_count":3224,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":492,"mirror_url":null,"open_issues_count":104,"forks":492,"open_issues":104,"watchers":3224,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lostisland/faraday/pulls/604"},"html":{"href":"https://github.com/lostisland/faraday/pull/604"},"issue":{"href":"https://api.github.com/repos/lostisland/faraday/issues/604"},"comments":{"href":"https://api.github.com/repos/lostisland/faraday/issues/604/comments"},"review_comments":{"href":"https://api.github.com/repos/lostisland/faraday/pulls/604/comments"},"review_comment":{"href":"https://api.github.com/repos/lostisland/faraday/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lostisland/faraday/pulls/604/commits"},"statuses":{"href":"https://api.github.com/repos/lostisland/faraday/statuses/60cdd853545a06a19fd9cd771bbace1196cea141"}}}}
{"actor":{"display_login":"grosser"}}