{"action":"created","comment":{"url":"https://api.github.com/repos/shazow/urllib3/pulls/comments/76130219","id":76130219,"diff_hunk":"@@ -182,6 +192,38 @@ def tell(self):\n         \"\"\"\n         return self._fp_bytes_read\n \n+    def _init_length(self, request_method):\n+        \"\"\"\n+        Set initial length value for Response content.\n+\n+        Logic extracted from httplib.py in the standard Python library.\n+        \"\"\"\n+        length = self.headers.get('content-length')\n+        if length is not None and not self.chunked:\n+            try:\n+                length = int(length)","path":"urllib3/response.py","position":62,"original_position":62,"commit_id":"2015f77a97d4e06cab645a786837b65179675ac8","original_commit_id":"2015f77a97d4e06cab645a786837b65179675ac8","user":{"login":"nateprewitt","id":5271761,"avatar_url":"https://avatars.githubusercontent.com/u/5271761?v=3","gravatar_id":"","url":"https://api.github.com/users/nateprewitt","html_url":"https://github.com/nateprewitt","followers_url":"https://api.github.com/users/nateprewitt/followers","following_url":"https://api.github.com/users/nateprewitt/following{/other_user}","gists_url":"https://api.github.com/users/nateprewitt/gists{/gist_id}","starred_url":"https://api.github.com/users/nateprewitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nateprewitt/subscriptions","organizations_url":"https://api.github.com/users/nateprewitt/orgs","repos_url":"https://api.github.com/users/nateprewitt/repos","events_url":"https://api.github.com/users/nateprewitt/events{/privacy}","received_events_url":"https://api.github.com/users/nateprewitt/received_events","type":"User","site_admin":false},"body":"By rejecting, do you mean raising an exception in that event instead of setting `length` to None?\r\n\r\nIf we want to handle the case (which I think would be better than the exception), something like:\r\n\r\n```python\r\nsingle_length = length.split(',')[0].strip()\r\nlength = int(single_length)\r\n```\r\nshould work, right?","created_at":"2016-08-24T20:14:14Z","updated_at":"2016-08-24T20:14:14Z","html_url":"https://github.com/shazow/urllib3/pull/949#discussion_r76130219","pull_request_url":"https://api.github.com/repos/shazow/urllib3/pulls/949","_links":{"self":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/comments/76130219"},"html":{"href":"https://github.com/shazow/urllib3/pull/949#discussion_r76130219"},"pull_request":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/949"}}},"pull_request":{"url":"https://api.github.com/repos/shazow/urllib3/pulls/949","id":81696798,"html_url":"https://github.com/shazow/urllib3/pull/949","diff_url":"https://github.com/shazow/urllib3/pull/949.diff","patch_url":"https://github.com/shazow/urllib3/pull/949.patch","issue_url":"https://api.github.com/repos/shazow/urllib3/issues/949","number":949,"state":"open","locked":false,"title":"strict_content_length enforcement","user":{"login":"nateprewitt","id":5271761,"avatar_url":"https://avatars.githubusercontent.com/u/5271761?v=3","gravatar_id":"","url":"https://api.github.com/users/nateprewitt","html_url":"https://github.com/nateprewitt","followers_url":"https://api.github.com/users/nateprewitt/followers","following_url":"https://api.github.com/users/nateprewitt/following{/other_user}","gists_url":"https://api.github.com/users/nateprewitt/gists{/gist_id}","starred_url":"https://api.github.com/users/nateprewitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nateprewitt/subscriptions","organizations_url":"https://api.github.com/users/nateprewitt/orgs","repos_url":"https://api.github.com/users/nateprewitt/repos","events_url":"https://api.github.com/users/nateprewitt/events{/privacy}","received_events_url":"https://api.github.com/users/nateprewitt/received_events","type":"User","site_admin":false},"body":"So here's a pass at #723. This is kind of a weird edge case but it particularly prominent in the default configuration of Requests. Most calls performed by `urllib3` will raise a `IncompleteRead` error from `httplib` when the number of bytes in the body doesn't match the `Content-Length`. \r\n\r\nThe Skinny\r\n========\r\n`httplib` raises `IncompleteRead`s appropriately everywhere except on incrementally read data. This is the primary way Requests uses `urlopen` with `preload_content=False` and then reading with `iter_content()`. Retrieving data this way hits the flaw in `httplib`. I've added a flag to enable this functionality, so as not to break `stream(amt)` and `read(amt)` calls presently. In the next major release, I would advise the flag being removed to make all `read` operations uniform by default.\r\n\r\nNotes:\r\n\r\n* My unfamiliarity with the testing harness is definitely showing in `test_strict_content_length` but the test does prove the changes are working correctly. Tornado won't allow you to send uneven data, so this was the only other solution I could come up with. Any suggestions on alternative methods of simulating this problem would be appreciated.\r\n\r\n* ~~I implemented `length` as a property to match the attribute nature of `httplib.HTTPResponse.length`. I realize an int that we modify may be preferred to a property, but felt it would be more likely to break if we implement int updates everywhere IO might happen in the code.~~","created_at":"2016-08-17T18:56:19Z","updated_at":"2016-08-24T20:14:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aeecaf5371f0db9f6c1f7e7cb502b7110ba7f54e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/shazow/urllib3/pulls/949/commits","review_comments_url":"https://api.github.com/repos/shazow/urllib3/pulls/949/comments","review_comment_url":"https://api.github.com/repos/shazow/urllib3/pulls/comments{/number}","comments_url":"https://api.github.com/repos/shazow/urllib3/issues/949/comments","statuses_url":"https://api.github.com/repos/shazow/urllib3/statuses/2015f77a97d4e06cab645a786837b65179675ac8","head":{"label":"nateprewitt:723_strict_content_length","ref":"723_strict_content_length","sha":"2015f77a97d4e06cab645a786837b65179675ac8","user":{"login":"nateprewitt","id":5271761,"avatar_url":"https://avatars.githubusercontent.com/u/5271761?v=3","gravatar_id":"","url":"https://api.github.com/users/nateprewitt","html_url":"https://github.com/nateprewitt","followers_url":"https://api.github.com/users/nateprewitt/followers","following_url":"https://api.github.com/users/nateprewitt/following{/other_user}","gists_url":"https://api.github.com/users/nateprewitt/gists{/gist_id}","starred_url":"https://api.github.com/users/nateprewitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nateprewitt/subscriptions","organizations_url":"https://api.github.com/users/nateprewitt/orgs","repos_url":"https://api.github.com/users/nateprewitt/repos","events_url":"https://api.github.com/users/nateprewitt/events{/privacy}","received_events_url":"https://api.github.com/users/nateprewitt/received_events","type":"User","site_admin":false},"repo":{"id":63372216,"name":"urllib3","full_name":"nateprewitt/urllib3","owner":{"login":"nateprewitt","id":5271761,"avatar_url":"https://avatars.githubusercontent.com/u/5271761?v=3","gravatar_id":"","url":"https://api.github.com/users/nateprewitt","html_url":"https://github.com/nateprewitt","followers_url":"https://api.github.com/users/nateprewitt/followers","following_url":"https://api.github.com/users/nateprewitt/following{/other_user}","gists_url":"https://api.github.com/users/nateprewitt/gists{/gist_id}","starred_url":"https://api.github.com/users/nateprewitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nateprewitt/subscriptions","organizations_url":"https://api.github.com/users/nateprewitt/orgs","repos_url":"https://api.github.com/users/nateprewitt/repos","events_url":"https://api.github.com/users/nateprewitt/events{/privacy}","received_events_url":"https://api.github.com/users/nateprewitt/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nateprewitt/urllib3","description":"Python HTTP library with thread-safe connection pooling, file post support, sanity friendly, and more.","fork":true,"url":"https://api.github.com/repos/nateprewitt/urllib3","forks_url":"https://api.github.com/repos/nateprewitt/urllib3/forks","keys_url":"https://api.github.com/repos/nateprewitt/urllib3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nateprewitt/urllib3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nateprewitt/urllib3/teams","hooks_url":"https://api.github.com/repos/nateprewitt/urllib3/hooks","issue_events_url":"https://api.github.com/repos/nateprewitt/urllib3/issues/events{/number}","events_url":"https://api.github.com/repos/nateprewitt/urllib3/events","assignees_url":"https://api.github.com/repos/nateprewitt/urllib3/assignees{/user}","branches_url":"https://api.github.com/repos/nateprewitt/urllib3/branches{/branch}","tags_url":"https://api.github.com/repos/nateprewitt/urllib3/tags","blobs_url":"https://api.github.com/repos/nateprewitt/urllib3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nateprewitt/urllib3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nateprewitt/urllib3/git/refs{/sha}","trees_url":"https://api.github.com/repos/nateprewitt/urllib3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nateprewitt/urllib3/statuses/{sha}","languages_url":"https://api.github.com/repos/nateprewitt/urllib3/languages","stargazers_url":"https://api.github.com/repos/nateprewitt/urllib3/stargazers","contributors_url":"https://api.github.com/repos/nateprewitt/urllib3/contributors","subscribers_url":"https://api.github.com/repos/nateprewitt/urllib3/subscribers","subscription_url":"https://api.github.com/repos/nateprewitt/urllib3/subscription","commits_url":"https://api.github.com/repos/nateprewitt/urllib3/commits{/sha}","git_commits_url":"https://api.github.com/repos/nateprewitt/urllib3/git/commits{/sha}","comments_url":"https://api.github.com/repos/nateprewitt/urllib3/comments{/number}","issue_comment_url":"https://api.github.com/repos/nateprewitt/urllib3/issues/comments{/number}","contents_url":"https://api.github.com/repos/nateprewitt/urllib3/contents/{+path}","compare_url":"https://api.github.com/repos/nateprewitt/urllib3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nateprewitt/urllib3/merges","archive_url":"https://api.github.com/repos/nateprewitt/urllib3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nateprewitt/urllib3/downloads","issues_url":"https://api.github.com/repos/nateprewitt/urllib3/issues{/number}","pulls_url":"https://api.github.com/repos/nateprewitt/urllib3/pulls{/number}","milestones_url":"https://api.github.com/repos/nateprewitt/urllib3/milestones{/number}","notifications_url":"https://api.github.com/repos/nateprewitt/urllib3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nateprewitt/urllib3/labels{/name}","releases_url":"https://api.github.com/repos/nateprewitt/urllib3/releases{/id}","deployments_url":"https://api.github.com/repos/nateprewitt/urllib3/deployments","created_at":"2016-07-14T21:50:59Z","updated_at":"2016-07-14T21:51:00Z","pushed_at":"2016-08-23T21:38:12Z","git_url":"git://github.com/nateprewitt/urllib3.git","ssh_url":"git@github.com:nateprewitt/urllib3.git","clone_url":"https://github.com/nateprewitt/urllib3.git","svn_url":"https://github.com/nateprewitt/urllib3","homepage":"https://urllib3.readthedocs.io/","size":2693,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"shazow:master","ref":"master","sha":"d53eccf27c3871d9b730068a4165275815ba23d2","user":{"login":"shazow","id":6292,"avatar_url":"https://avatars.githubusercontent.com/u/6292?v=3","gravatar_id":"","url":"https://api.github.com/users/shazow","html_url":"https://github.com/shazow","followers_url":"https://api.github.com/users/shazow/followers","following_url":"https://api.github.com/users/shazow/following{/other_user}","gists_url":"https://api.github.com/users/shazow/gists{/gist_id}","starred_url":"https://api.github.com/users/shazow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shazow/subscriptions","organizations_url":"https://api.github.com/users/shazow/orgs","repos_url":"https://api.github.com/users/shazow/repos","events_url":"https://api.github.com/users/shazow/events{/privacy}","received_events_url":"https://api.github.com/users/shazow/received_events","type":"User","site_admin":false},"repo":{"id":2410676,"name":"urllib3","full_name":"shazow/urllib3","owner":{"login":"shazow","id":6292,"avatar_url":"https://avatars.githubusercontent.com/u/6292?v=3","gravatar_id":"","url":"https://api.github.com/users/shazow","html_url":"https://github.com/shazow","followers_url":"https://api.github.com/users/shazow/followers","following_url":"https://api.github.com/users/shazow/following{/other_user}","gists_url":"https://api.github.com/users/shazow/gists{/gist_id}","starred_url":"https://api.github.com/users/shazow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shazow/subscriptions","organizations_url":"https://api.github.com/users/shazow/orgs","repos_url":"https://api.github.com/users/shazow/repos","events_url":"https://api.github.com/users/shazow/events{/privacy}","received_events_url":"https://api.github.com/users/shazow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shazow/urllib3","description":"Python HTTP library with thread-safe connection pooling, file post support, sanity friendly, and more.","fork":false,"url":"https://api.github.com/repos/shazow/urllib3","forks_url":"https://api.github.com/repos/shazow/urllib3/forks","keys_url":"https://api.github.com/repos/shazow/urllib3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shazow/urllib3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shazow/urllib3/teams","hooks_url":"https://api.github.com/repos/shazow/urllib3/hooks","issue_events_url":"https://api.github.com/repos/shazow/urllib3/issues/events{/number}","events_url":"https://api.github.com/repos/shazow/urllib3/events","assignees_url":"https://api.github.com/repos/shazow/urllib3/assignees{/user}","branches_url":"https://api.github.com/repos/shazow/urllib3/branches{/branch}","tags_url":"https://api.github.com/repos/shazow/urllib3/tags","blobs_url":"https://api.github.com/repos/shazow/urllib3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shazow/urllib3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shazow/urllib3/git/refs{/sha}","trees_url":"https://api.github.com/repos/shazow/urllib3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shazow/urllib3/statuses/{sha}","languages_url":"https://api.github.com/repos/shazow/urllib3/languages","stargazers_url":"https://api.github.com/repos/shazow/urllib3/stargazers","contributors_url":"https://api.github.com/repos/shazow/urllib3/contributors","subscribers_url":"https://api.github.com/repos/shazow/urllib3/subscribers","subscription_url":"https://api.github.com/repos/shazow/urllib3/subscription","commits_url":"https://api.github.com/repos/shazow/urllib3/commits{/sha}","git_commits_url":"https://api.github.com/repos/shazow/urllib3/git/commits{/sha}","comments_url":"https://api.github.com/repos/shazow/urllib3/comments{/number}","issue_comment_url":"https://api.github.com/repos/shazow/urllib3/issues/comments{/number}","contents_url":"https://api.github.com/repos/shazow/urllib3/contents/{+path}","compare_url":"https://api.github.com/repos/shazow/urllib3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shazow/urllib3/merges","archive_url":"https://api.github.com/repos/shazow/urllib3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shazow/urllib3/downloads","issues_url":"https://api.github.com/repos/shazow/urllib3/issues{/number}","pulls_url":"https://api.github.com/repos/shazow/urllib3/pulls{/number}","milestones_url":"https://api.github.com/repos/shazow/urllib3/milestones{/number}","notifications_url":"https://api.github.com/repos/shazow/urllib3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shazow/urllib3/labels{/name}","releases_url":"https://api.github.com/repos/shazow/urllib3/releases{/id}","deployments_url":"https://api.github.com/repos/shazow/urllib3/deployments","created_at":"2011-09-18T18:08:28Z","updated_at":"2016-08-24T18:47:15Z","pushed_at":"2016-08-24T14:23:31Z","git_url":"git://github.com/shazow/urllib3.git","ssh_url":"git@github.com:shazow/urllib3.git","clone_url":"https://github.com/shazow/urllib3.git","svn_url":"https://github.com/shazow/urllib3","homepage":"https://urllib3.readthedocs.io/","size":4727,"stargazers_count":1107,"watchers_count":1107,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":368,"mirror_url":null,"open_issues_count":128,"forks":368,"open_issues":128,"watchers":1107,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/949"},"html":{"href":"https://github.com/shazow/urllib3/pull/949"},"issue":{"href":"https://api.github.com/repos/shazow/urllib3/issues/949"},"comments":{"href":"https://api.github.com/repos/shazow/urllib3/issues/949/comments"},"review_comments":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/949/comments"},"review_comment":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/949/commits"},"statuses":{"href":"https://api.github.com/repos/shazow/urllib3/statuses/2015f77a97d4e06cab645a786837b65179675ac8"}}}}
{"actor":{"display_login":"nateprewitt"}}