{"action":"created","comment":{"url":"https://api.github.com/repos/esp8266/Arduino/pulls/comments/48637028","id":48637028,"diff_hunk":"@@ -468,61 +470,36 @@ int HTTPClient::writeToStream(Stream * stream) {\n \n     // get length of document (is -1 when Server sends no Content-Length header)\n     int len = _size;\n-    int bytesWritten = 0;\n-\n-    size_t buff_size = HTTP_TCP_BUFFER_SIZE;\n-\n-    // if possible create smaller buffer then HTTP_TCP_BUFFER_SIZE\n-    if((len > 0) && (len < HTTP_TCP_BUFFER_SIZE)) {\n-        buff_size = len;\n-    }\n-\n-    // create buffer for read\n-    uint8_t * buff = (uint8_t *) malloc(buff_size);\n-\n-    if(buff) {\n-        // read all data from server\n-        while(connected() && (len > 0 || len == -1)) {\n-\n-            // get available data size\n-            size_t size = _tcp->available();\n-\n-            if(size) {\n-                int c = _tcp->readBytes(buff, ((size > buff_size) ? buff_size : size));\n-\n-                // write it to Stream\n-                int w = stream->write(buff, c);\n-                bytesWritten += w;\n-                if(w != c) {\n-                    DEBUG_HTTPCLIENT(\"[HTTP-Client][writeToStream] short write asked for %d but got %d\\n\", c, w);\n-                    break;\n-                }\n-\n-                if(len > 0) {\n-                    len -= c;\n+    int ret = 0;\n+\n+    if(_transferEncoding == HTTPC_TE_IDENTITY) {\n+        ret = writeToStreamDataBlock(stream, len);\n+    } else if(_transferEncoding == HTTPC_TE_CHUNKED) {\n+        while(1) {\n+            String chunkHeader = _tcp->readStringUntil('\\n');\n+            chunkHeader.trim(); // remove \\r\n+\n+            // read size of chunk\n+            len = (uint32_t) strtol((const char *) chunkHeader.c_str(), NULL, 16);\n+            DEBUG_HTTPCLIENT(\"[HTTP-Client] read chunk len: %d\\n\", len);\n+            if(len > 0) {\n+                int r = writeToStreamDataBlock(stream, len);","path":"libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp","position":67,"original_position":67,"commit_id":"9c923ecb9a4f6d2170a8d209d79d4d8cd0c92665","original_commit_id":"9c923ecb9a4f6d2170a8d209d79d4d8cd0c92665","user":{"login":"gtalusan","id":355585,"avatar_url":"https://avatars.githubusercontent.com/u/355585?v=3","gravatar_id":"","url":"https://api.github.com/users/gtalusan","html_url":"https://github.com/gtalusan","followers_url":"https://api.github.com/users/gtalusan/followers","following_url":"https://api.github.com/users/gtalusan/following{/other_user}","gists_url":"https://api.github.com/users/gtalusan/gists{/gist_id}","starred_url":"https://api.github.com/users/gtalusan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gtalusan/subscriptions","organizations_url":"https://api.github.com/users/gtalusan/orgs","repos_url":"https://api.github.com/users/gtalusan/repos","events_url":"https://api.github.com/users/gtalusan/events{/privacy}","received_events_url":"https://api.github.com/users/gtalusan/received_events","type":"User","site_admin":false},"body":"Should this check if r != len to handle short writes?  If there's a short write then it looks like this'll continue to iterate over the response.","created_at":"2015-12-30T22:44:01Z","updated_at":"2015-12-30T22:44:01Z","html_url":"https://github.com/esp8266/Arduino/pull/1333#discussion_r48637028","pull_request_url":"https://api.github.com/repos/esp8266/Arduino/pulls/1333","_links":{"self":{"href":"https://api.github.com/repos/esp8266/Arduino/pulls/comments/48637028"},"html":{"href":"https://github.com/esp8266/Arduino/pull/1333#discussion_r48637028"},"pull_request":{"href":"https://api.github.com/repos/esp8266/Arduino/pulls/1333"}}},"pull_request":{"url":"https://api.github.com/repos/esp8266/Arduino/pulls/1333","id":54826872,"html_url":"https://github.com/esp8266/Arduino/pull/1333","diff_url":"https://github.com/esp8266/Arduino/pull/1333.diff","patch_url":"https://github.com/esp8266/Arduino/pull/1333.patch","issue_url":"https://api.github.com/repos/esp8266/Arduino/issues/1333","number":1333,"state":"open","locked":false,"title":"HTTPclient - add CHUNKED encoding support","user":{"login":"Links2004","id":974709,"avatar_url":"https://avatars.githubusercontent.com/u/974709?v=3","gravatar_id":"","url":"https://api.github.com/users/Links2004","html_url":"https://github.com/Links2004","followers_url":"https://api.github.com/users/Links2004/followers","following_url":"https://api.github.com/users/Links2004/following{/other_user}","gists_url":"https://api.github.com/users/Links2004/gists{/gist_id}","starred_url":"https://api.github.com/users/Links2004/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Links2004/subscriptions","organizations_url":"https://api.github.com/users/Links2004/orgs","repos_url":"https://api.github.com/users/Links2004/repos","events_url":"https://api.github.com/users/Links2004/events{/privacy}","received_events_url":"https://api.github.com/users/Links2004/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-30T20:23:08Z","updated_at":"2015-12-30T22:44:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fb416c27d05ee66dc47e644031dcc602a9a9bf36","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/esp8266/Arduino/pulls/1333/commits","review_comments_url":"https://api.github.com/repos/esp8266/Arduino/pulls/1333/comments","review_comment_url":"https://api.github.com/repos/esp8266/Arduino/pulls/comments{/number}","comments_url":"https://api.github.com/repos/esp8266/Arduino/issues/1333/comments","statuses_url":"https://api.github.com/repos/esp8266/Arduino/statuses/9c923ecb9a4f6d2170a8d209d79d4d8cd0c92665","head":{"label":"Links2004:httpClient","ref":"httpClient","sha":"9c923ecb9a4f6d2170a8d209d79d4d8cd0c92665","user":{"login":"Links2004","id":974709,"avatar_url":"https://avatars.githubusercontent.com/u/974709?v=3","gravatar_id":"","url":"https://api.github.com/users/Links2004","html_url":"https://github.com/Links2004","followers_url":"https://api.github.com/users/Links2004/followers","following_url":"https://api.github.com/users/Links2004/following{/other_user}","gists_url":"https://api.github.com/users/Links2004/gists{/gist_id}","starred_url":"https://api.github.com/users/Links2004/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Links2004/subscriptions","organizations_url":"https://api.github.com/users/Links2004/orgs","repos_url":"https://api.github.com/users/Links2004/repos","events_url":"https://api.github.com/users/Links2004/events{/privacy}","received_events_url":"https://api.github.com/users/Links2004/received_events","type":"User","site_admin":false},"repo":{"id":45296847,"name":"Arduino","full_name":"Links2004/Arduino","owner":{"login":"Links2004","id":974709,"avatar_url":"https://avatars.githubusercontent.com/u/974709?v=3","gravatar_id":"","url":"https://api.github.com/users/Links2004","html_url":"https://github.com/Links2004","followers_url":"https://api.github.com/users/Links2004/followers","following_url":"https://api.github.com/users/Links2004/following{/other_user}","gists_url":"https://api.github.com/users/Links2004/gists{/gist_id}","starred_url":"https://api.github.com/users/Links2004/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Links2004/subscriptions","organizations_url":"https://api.github.com/users/Links2004/orgs","repos_url":"https://api.github.com/users/Links2004/repos","events_url":"https://api.github.com/users/Links2004/events{/privacy}","received_events_url":"https://api.github.com/users/Links2004/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Links2004/Arduino","description":"ESP8266 core for Arduino","fork":true,"url":"https://api.github.com/repos/Links2004/Arduino","forks_url":"https://api.github.com/repos/Links2004/Arduino/forks","keys_url":"https://api.github.com/repos/Links2004/Arduino/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Links2004/Arduino/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Links2004/Arduino/teams","hooks_url":"https://api.github.com/repos/Links2004/Arduino/hooks","issue_events_url":"https://api.github.com/repos/Links2004/Arduino/issues/events{/number}","events_url":"https://api.github.com/repos/Links2004/Arduino/events","assignees_url":"https://api.github.com/repos/Links2004/Arduino/assignees{/user}","branches_url":"https://api.github.com/repos/Links2004/Arduino/branches{/branch}","tags_url":"https://api.github.com/repos/Links2004/Arduino/tags","blobs_url":"https://api.github.com/repos/Links2004/Arduino/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Links2004/Arduino/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Links2004/Arduino/git/refs{/sha}","trees_url":"https://api.github.com/repos/Links2004/Arduino/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Links2004/Arduino/statuses/{sha}","languages_url":"https://api.github.com/repos/Links2004/Arduino/languages","stargazers_url":"https://api.github.com/repos/Links2004/Arduino/stargazers","contributors_url":"https://api.github.com/repos/Links2004/Arduino/contributors","subscribers_url":"https://api.github.com/repos/Links2004/Arduino/subscribers","subscription_url":"https://api.github.com/repos/Links2004/Arduino/subscription","commits_url":"https://api.github.com/repos/Links2004/Arduino/commits{/sha}","git_commits_url":"https://api.github.com/repos/Links2004/Arduino/git/commits{/sha}","comments_url":"https://api.github.com/repos/Links2004/Arduino/comments{/number}","issue_comment_url":"https://api.github.com/repos/Links2004/Arduino/issues/comments{/number}","contents_url":"https://api.github.com/repos/Links2004/Arduino/contents/{+path}","compare_url":"https://api.github.com/repos/Links2004/Arduino/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Links2004/Arduino/merges","archive_url":"https://api.github.com/repos/Links2004/Arduino/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Links2004/Arduino/downloads","issues_url":"https://api.github.com/repos/Links2004/Arduino/issues{/number}","pulls_url":"https://api.github.com/repos/Links2004/Arduino/pulls{/number}","milestones_url":"https://api.github.com/repos/Links2004/Arduino/milestones{/number}","notifications_url":"https://api.github.com/repos/Links2004/Arduino/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Links2004/Arduino/labels{/name}","releases_url":"https://api.github.com/repos/Links2004/Arduino/releases{/id}","created_at":"2015-10-31T09:59:33Z","updated_at":"2015-12-19T12:13:23Z","pushed_at":"2015-12-30T20:22:33Z","git_url":"git://github.com/Links2004/Arduino.git","ssh_url":"git@github.com:Links2004/Arduino.git","clone_url":"https://github.com/Links2004/Arduino.git","svn_url":"https://github.com/Links2004/Arduino","homepage":"","size":16739,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"esp8266:master","ref":"master","sha":"35a46b95a5dede5626c9bba4e998f3e1982a93e9","user":{"login":"esp8266","id":8943775,"avatar_url":"https://avatars.githubusercontent.com/u/8943775?v=3","gravatar_id":"","url":"https://api.github.com/users/esp8266","html_url":"https://github.com/esp8266","followers_url":"https://api.github.com/users/esp8266/followers","following_url":"https://api.github.com/users/esp8266/following{/other_user}","gists_url":"https://api.github.com/users/esp8266/gists{/gist_id}","starred_url":"https://api.github.com/users/esp8266/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/esp8266/subscriptions","organizations_url":"https://api.github.com/users/esp8266/orgs","repos_url":"https://api.github.com/users/esp8266/repos","events_url":"https://api.github.com/users/esp8266/events{/privacy}","received_events_url":"https://api.github.com/users/esp8266/received_events","type":"Organization","site_admin":false},"repo":{"id":32969220,"name":"Arduino","full_name":"esp8266/Arduino","owner":{"login":"esp8266","id":8943775,"avatar_url":"https://avatars.githubusercontent.com/u/8943775?v=3","gravatar_id":"","url":"https://api.github.com/users/esp8266","html_url":"https://github.com/esp8266","followers_url":"https://api.github.com/users/esp8266/followers","following_url":"https://api.github.com/users/esp8266/following{/other_user}","gists_url":"https://api.github.com/users/esp8266/gists{/gist_id}","starred_url":"https://api.github.com/users/esp8266/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/esp8266/subscriptions","organizations_url":"https://api.github.com/users/esp8266/orgs","repos_url":"https://api.github.com/users/esp8266/repos","events_url":"https://api.github.com/users/esp8266/events{/privacy}","received_events_url":"https://api.github.com/users/esp8266/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/esp8266/Arduino","description":"ESP8266 core for Arduino","fork":false,"url":"https://api.github.com/repos/esp8266/Arduino","forks_url":"https://api.github.com/repos/esp8266/Arduino/forks","keys_url":"https://api.github.com/repos/esp8266/Arduino/keys{/key_id}","collaborators_url":"https://api.github.com/repos/esp8266/Arduino/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/esp8266/Arduino/teams","hooks_url":"https://api.github.com/repos/esp8266/Arduino/hooks","issue_events_url":"https://api.github.com/repos/esp8266/Arduino/issues/events{/number}","events_url":"https://api.github.com/repos/esp8266/Arduino/events","assignees_url":"https://api.github.com/repos/esp8266/Arduino/assignees{/user}","branches_url":"https://api.github.com/repos/esp8266/Arduino/branches{/branch}","tags_url":"https://api.github.com/repos/esp8266/Arduino/tags","blobs_url":"https://api.github.com/repos/esp8266/Arduino/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/esp8266/Arduino/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/esp8266/Arduino/git/refs{/sha}","trees_url":"https://api.github.com/repos/esp8266/Arduino/git/trees{/sha}","statuses_url":"https://api.github.com/repos/esp8266/Arduino/statuses/{sha}","languages_url":"https://api.github.com/repos/esp8266/Arduino/languages","stargazers_url":"https://api.github.com/repos/esp8266/Arduino/stargazers","contributors_url":"https://api.github.com/repos/esp8266/Arduino/contributors","subscribers_url":"https://api.github.com/repos/esp8266/Arduino/subscribers","subscription_url":"https://api.github.com/repos/esp8266/Arduino/subscription","commits_url":"https://api.github.com/repos/esp8266/Arduino/commits{/sha}","git_commits_url":"https://api.github.com/repos/esp8266/Arduino/git/commits{/sha}","comments_url":"https://api.github.com/repos/esp8266/Arduino/comments{/number}","issue_comment_url":"https://api.github.com/repos/esp8266/Arduino/issues/comments{/number}","contents_url":"https://api.github.com/repos/esp8266/Arduino/contents/{+path}","compare_url":"https://api.github.com/repos/esp8266/Arduino/compare/{base}...{head}","merges_url":"https://api.github.com/repos/esp8266/Arduino/merges","archive_url":"https://api.github.com/repos/esp8266/Arduino/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/esp8266/Arduino/downloads","issues_url":"https://api.github.com/repos/esp8266/Arduino/issues{/number}","pulls_url":"https://api.github.com/repos/esp8266/Arduino/pulls{/number}","milestones_url":"https://api.github.com/repos/esp8266/Arduino/milestones{/number}","notifications_url":"https://api.github.com/repos/esp8266/Arduino/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/esp8266/Arduino/labels{/name}","releases_url":"https://api.github.com/repos/esp8266/Arduino/releases{/id}","created_at":"2015-03-27T05:22:06Z","updated_at":"2015-12-30T22:31:49Z","pushed_at":"2015-12-30T20:23:09Z","git_url":"git://github.com/esp8266/Arduino.git","ssh_url":"git@github.com:esp8266/Arduino.git","clone_url":"https://github.com/esp8266/Arduino.git","svn_url":"https://github.com/esp8266/Arduino","homepage":"","size":1571346,"stargazers_count":1709,"watchers_count":1709,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":672,"mirror_url":null,"open_issues_count":222,"forks":672,"open_issues":222,"watchers":1709,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/esp8266/Arduino/pulls/1333"},"html":{"href":"https://github.com/esp8266/Arduino/pull/1333"},"issue":{"href":"https://api.github.com/repos/esp8266/Arduino/issues/1333"},"comments":{"href":"https://api.github.com/repos/esp8266/Arduino/issues/1333/comments"},"review_comments":{"href":"https://api.github.com/repos/esp8266/Arduino/pulls/1333/comments"},"review_comment":{"href":"https://api.github.com/repos/esp8266/Arduino/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/esp8266/Arduino/pulls/1333/commits"},"statuses":{"href":"https://api.github.com/repos/esp8266/Arduino/statuses/9c923ecb9a4f6d2170a8d209d79d4d8cd0c92665"}}}}