{"action":"created","comment":{"url":"https://api.github.com/repos/httprb/http/pulls/comments/38826670","id":38826670,"diff_hunk":"@@ -65,24 +68,35 @@ def send_request_header\n         add_headers\n         add_body_type_headers\n \n-        @socket << join_headers\n+        write(join_headers)\n       end\n \n       def send_request_body\n         if @body.is_a?(String)\n-          @socket << @body\n+          write(@body)\n         elsif @body.is_a?(Enumerable)\n           @body.each do |chunk|\n-            @socket << chunk.bytesize.to_s(16) << CRLF\n-            @socket << chunk << CRLF\n+            write(chunk.bytesize.to_s(16) << CRLF)\n+            write(chunk << CRLF)\n           end\n \n-          @socket << ZERO << CRLF << CRLF\n+          write(CHUNKED_END)\n         end\n       end\n \n       private\n \n+      def write(data)\n+        while data.present?\n+          length = @socket.write(data)\n+          if data.length > length\n+            data = data[length..-1]","path":"lib/http/request/writer.rb","position":50,"original_position":50,"commit_id":"7869ff2ba20d46ceec5e2f22058be3b74b433150","original_commit_id":"7869ff2ba20d46ceec5e2f22058be3b74b433150","user":{"login":"tarcieri","id":797,"avatar_url":"https://avatars.githubusercontent.com/u/797?v=3","gravatar_id":"","url":"https://api.github.com/users/tarcieri","html_url":"https://github.com/tarcieri","followers_url":"https://api.github.com/users/tarcieri/followers","following_url":"https://api.github.com/users/tarcieri/following{/other_user}","gists_url":"https://api.github.com/users/tarcieri/gists{/gist_id}","starred_url":"https://api.github.com/users/tarcieri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tarcieri/subscriptions","organizations_url":"https://api.github.com/users/tarcieri/orgs","repos_url":"https://api.github.com/users/tarcieri/repos","events_url":"https://api.github.com/users/tarcieri/events{/privacy}","received_events_url":"https://api.github.com/users/tarcieri/received_events","type":"User","site_admin":false},"body":"This will allocate every time. I wonder if it would be possible to use `#slice!` here to reduce allocations. Or maybe we just need real `ByteBuffers` :confused:","created_at":"2015-09-06T22:00:40Z","updated_at":"2015-09-06T22:00:40Z","html_url":"https://github.com/httprb/http/pull/252#discussion_r38826670","pull_request_url":"https://api.github.com/repos/httprb/http/pulls/252","_links":{"self":{"href":"https://api.github.com/repos/httprb/http/pulls/comments/38826670"},"html":{"href":"https://github.com/httprb/http/pull/252#discussion_r38826670"},"pull_request":{"href":"https://api.github.com/repos/httprb/http/pulls/252"}}},"pull_request":{"url":"https://api.github.com/repos/httprb/http/pulls/252","id":44309868,"html_url":"https://github.com/httprb/http/pull/252","diff_url":"https://github.com/httprb/http/pull/252.diff","patch_url":"https://github.com/httprb/http/pull/252.patch","issue_url":"https://api.github.com/repos/httprb/http/issues/252","number":252,"state":"closed","locked":false,"title":"Fixed chunk writing if the data is bugger than our buffer (#251)","user":{"login":"zanker","id":323517,"avatar_url":"https://avatars.githubusercontent.com/u/323517?v=3","gravatar_id":"","url":"https://api.github.com/users/zanker","html_url":"https://github.com/zanker","followers_url":"https://api.github.com/users/zanker/followers","following_url":"https://api.github.com/users/zanker/following{/other_user}","gists_url":"https://api.github.com/users/zanker/gists{/gist_id}","starred_url":"https://api.github.com/users/zanker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zanker/subscriptions","organizations_url":"https://api.github.com/users/zanker/orgs","repos_url":"https://api.github.com/users/zanker/repos","events_url":"https://api.github.com/users/zanker/events{/privacy}","received_events_url":"https://api.github.com/users/zanker/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-06T21:02:46Z","updated_at":"2015-09-06T22:00:40Z","closed_at":"2015-09-06T21:44:01Z","merged_at":"2015-09-06T21:44:01Z","merge_commit_sha":"3a962561f8a32069db852e762221bbfb197ff38f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/httprb/http/pulls/252/commits","review_comments_url":"https://api.github.com/repos/httprb/http/pulls/252/comments","review_comment_url":"https://api.github.com/repos/httprb/http/pulls/comments{/number}","comments_url":"https://api.github.com/repos/httprb/http/issues/252/comments","statuses_url":"https://api.github.com/repos/httprb/http/statuses/7869ff2ba20d46ceec5e2f22058be3b74b433150","head":{"label":"httprb:zanker/stress-tests","ref":"zanker/stress-tests","sha":"7869ff2ba20d46ceec5e2f22058be3b74b433150","user":{"login":"httprb","id":10374575,"avatar_url":"https://avatars.githubusercontent.com/u/10374575?v=3","gravatar_id":"","url":"https://api.github.com/users/httprb","html_url":"https://github.com/httprb","followers_url":"https://api.github.com/users/httprb/followers","following_url":"https://api.github.com/users/httprb/following{/other_user}","gists_url":"https://api.github.com/users/httprb/gists{/gist_id}","starred_url":"https://api.github.com/users/httprb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/httprb/subscriptions","organizations_url":"https://api.github.com/users/httprb/orgs","repos_url":"https://api.github.com/users/httprb/repos","events_url":"https://api.github.com/users/httprb/events{/privacy}","received_events_url":"https://api.github.com/users/httprb/received_events","type":"Organization","site_admin":false},"repo":{"id":2524005,"name":"http","full_name":"httprb/http","owner":{"login":"httprb","id":10374575,"avatar_url":"https://avatars.githubusercontent.com/u/10374575?v=3","gravatar_id":"","url":"https://api.github.com/users/httprb","html_url":"https://github.com/httprb","followers_url":"https://api.github.com/users/httprb/followers","following_url":"https://api.github.com/users/httprb/following{/other_user}","gists_url":"https://api.github.com/users/httprb/gists{/gist_id}","starred_url":"https://api.github.com/users/httprb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/httprb/subscriptions","organizations_url":"https://api.github.com/users/httprb/orgs","repos_url":"https://api.github.com/users/httprb/repos","events_url":"https://api.github.com/users/httprb/events{/privacy}","received_events_url":"https://api.github.com/users/httprb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/httprb/http","description":"http.rb: a fast Ruby HTTP client with a chainable API and full streaming support","fork":false,"url":"https://api.github.com/repos/httprb/http","forks_url":"https://api.github.com/repos/httprb/http/forks","keys_url":"https://api.github.com/repos/httprb/http/keys{/key_id}","collaborators_url":"https://api.github.com/repos/httprb/http/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/httprb/http/teams","hooks_url":"https://api.github.com/repos/httprb/http/hooks","issue_events_url":"https://api.github.com/repos/httprb/http/issues/events{/number}","events_url":"https://api.github.com/repos/httprb/http/events","assignees_url":"https://api.github.com/repos/httprb/http/assignees{/user}","branches_url":"https://api.github.com/repos/httprb/http/branches{/branch}","tags_url":"https://api.github.com/repos/httprb/http/tags","blobs_url":"https://api.github.com/repos/httprb/http/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/httprb/http/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/httprb/http/git/refs{/sha}","trees_url":"https://api.github.com/repos/httprb/http/git/trees{/sha}","statuses_url":"https://api.github.com/repos/httprb/http/statuses/{sha}","languages_url":"https://api.github.com/repos/httprb/http/languages","stargazers_url":"https://api.github.com/repos/httprb/http/stargazers","contributors_url":"https://api.github.com/repos/httprb/http/contributors","subscribers_url":"https://api.github.com/repos/httprb/http/subscribers","subscription_url":"https://api.github.com/repos/httprb/http/subscription","commits_url":"https://api.github.com/repos/httprb/http/commits{/sha}","git_commits_url":"https://api.github.com/repos/httprb/http/git/commits{/sha}","comments_url":"https://api.github.com/repos/httprb/http/comments{/number}","issue_comment_url":"https://api.github.com/repos/httprb/http/issues/comments{/number}","contents_url":"https://api.github.com/repos/httprb/http/contents/{+path}","compare_url":"https://api.github.com/repos/httprb/http/compare/{base}...{head}","merges_url":"https://api.github.com/repos/httprb/http/merges","archive_url":"https://api.github.com/repos/httprb/http/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/httprb/http/downloads","issues_url":"https://api.github.com/repos/httprb/http/issues{/number}","pulls_url":"https://api.github.com/repos/httprb/http/pulls{/number}","milestones_url":"https://api.github.com/repos/httprb/http/milestones{/number}","notifications_url":"https://api.github.com/repos/httprb/http/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/httprb/http/labels{/name}","releases_url":"https://api.github.com/repos/httprb/http/releases{/id}","created_at":"2011-10-06T04:19:10Z","updated_at":"2015-09-04T17:27:29Z","pushed_at":"2015-09-06T21:57:08Z","git_url":"git://github.com/httprb/http.git","ssh_url":"git@github.com:httprb/http.git","clone_url":"https://github.com/httprb/http.git","svn_url":"https://github.com/httprb/http","homepage":"","size":3266,"stargazers_count":819,"watchers_count":819,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":81,"mirror_url":null,"open_issues_count":14,"forks":81,"open_issues":14,"watchers":819,"default_branch":"master"}},"base":{"label":"httprb:master","ref":"master","sha":"3bdea10258c21ec203d7b01cb67ab813b0cd4a44","user":{"login":"httprb","id":10374575,"avatar_url":"https://avatars.githubusercontent.com/u/10374575?v=3","gravatar_id":"","url":"https://api.github.com/users/httprb","html_url":"https://github.com/httprb","followers_url":"https://api.github.com/users/httprb/followers","following_url":"https://api.github.com/users/httprb/following{/other_user}","gists_url":"https://api.github.com/users/httprb/gists{/gist_id}","starred_url":"https://api.github.com/users/httprb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/httprb/subscriptions","organizations_url":"https://api.github.com/users/httprb/orgs","repos_url":"https://api.github.com/users/httprb/repos","events_url":"https://api.github.com/users/httprb/events{/privacy}","received_events_url":"https://api.github.com/users/httprb/received_events","type":"Organization","site_admin":false},"repo":{"id":2524005,"name":"http","full_name":"httprb/http","owner":{"login":"httprb","id":10374575,"avatar_url":"https://avatars.githubusercontent.com/u/10374575?v=3","gravatar_id":"","url":"https://api.github.com/users/httprb","html_url":"https://github.com/httprb","followers_url":"https://api.github.com/users/httprb/followers","following_url":"https://api.github.com/users/httprb/following{/other_user}","gists_url":"https://api.github.com/users/httprb/gists{/gist_id}","starred_url":"https://api.github.com/users/httprb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/httprb/subscriptions","organizations_url":"https://api.github.com/users/httprb/orgs","repos_url":"https://api.github.com/users/httprb/repos","events_url":"https://api.github.com/users/httprb/events{/privacy}","received_events_url":"https://api.github.com/users/httprb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/httprb/http","description":"http.rb: a fast Ruby HTTP client with a chainable API and full streaming support","fork":false,"url":"https://api.github.com/repos/httprb/http","forks_url":"https://api.github.com/repos/httprb/http/forks","keys_url":"https://api.github.com/repos/httprb/http/keys{/key_id}","collaborators_url":"https://api.github.com/repos/httprb/http/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/httprb/http/teams","hooks_url":"https://api.github.com/repos/httprb/http/hooks","issue_events_url":"https://api.github.com/repos/httprb/http/issues/events{/number}","events_url":"https://api.github.com/repos/httprb/http/events","assignees_url":"https://api.github.com/repos/httprb/http/assignees{/user}","branches_url":"https://api.github.com/repos/httprb/http/branches{/branch}","tags_url":"https://api.github.com/repos/httprb/http/tags","blobs_url":"https://api.github.com/repos/httprb/http/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/httprb/http/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/httprb/http/git/refs{/sha}","trees_url":"https://api.github.com/repos/httprb/http/git/trees{/sha}","statuses_url":"https://api.github.com/repos/httprb/http/statuses/{sha}","languages_url":"https://api.github.com/repos/httprb/http/languages","stargazers_url":"https://api.github.com/repos/httprb/http/stargazers","contributors_url":"https://api.github.com/repos/httprb/http/contributors","subscribers_url":"https://api.github.com/repos/httprb/http/subscribers","subscription_url":"https://api.github.com/repos/httprb/http/subscription","commits_url":"https://api.github.com/repos/httprb/http/commits{/sha}","git_commits_url":"https://api.github.com/repos/httprb/http/git/commits{/sha}","comments_url":"https://api.github.com/repos/httprb/http/comments{/number}","issue_comment_url":"https://api.github.com/repos/httprb/http/issues/comments{/number}","contents_url":"https://api.github.com/repos/httprb/http/contents/{+path}","compare_url":"https://api.github.com/repos/httprb/http/compare/{base}...{head}","merges_url":"https://api.github.com/repos/httprb/http/merges","archive_url":"https://api.github.com/repos/httprb/http/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/httprb/http/downloads","issues_url":"https://api.github.com/repos/httprb/http/issues{/number}","pulls_url":"https://api.github.com/repos/httprb/http/pulls{/number}","milestones_url":"https://api.github.com/repos/httprb/http/milestones{/number}","notifications_url":"https://api.github.com/repos/httprb/http/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/httprb/http/labels{/name}","releases_url":"https://api.github.com/repos/httprb/http/releases{/id}","created_at":"2011-10-06T04:19:10Z","updated_at":"2015-09-04T17:27:29Z","pushed_at":"2015-09-06T21:57:08Z","git_url":"git://github.com/httprb/http.git","ssh_url":"git@github.com:httprb/http.git","clone_url":"https://github.com/httprb/http.git","svn_url":"https://github.com/httprb/http","homepage":"","size":3266,"stargazers_count":819,"watchers_count":819,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":81,"mirror_url":null,"open_issues_count":14,"forks":81,"open_issues":14,"watchers":819,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/httprb/http/pulls/252"},"html":{"href":"https://github.com/httprb/http/pull/252"},"issue":{"href":"https://api.github.com/repos/httprb/http/issues/252"},"comments":{"href":"https://api.github.com/repos/httprb/http/issues/252/comments"},"review_comments":{"href":"https://api.github.com/repos/httprb/http/pulls/252/comments"},"review_comment":{"href":"https://api.github.com/repos/httprb/http/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/httprb/http/pulls/252/commits"},"statuses":{"href":"https://api.github.com/repos/httprb/http/statuses/7869ff2ba20d46ceec5e2f22058be3b74b433150"}}}}