Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9b7f1b22
Commit
9b7f1b22
authored
Dec 15, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
db81953f
b244deac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
2 deletions
+42
-2
Lib/http/client.py
Lib/http/client.py
+3
-0
Lib/test/test_httplib.py
Lib/test/test_httplib.py
+34
-2
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/http/client.py
View file @
9b7f1b22
...
...
@@ -536,6 +536,9 @@ class HTTPResponse(io.RawIOBase):
self
.
length
-=
n
if
not
self
.
length
:
self
.
close
()
else
:
if
not
n
:
self
.
close
()
return
n
def
_read_next_chunk_size
(
self
):
...
...
Lib/test/test_httplib.py
View file @
9b7f1b22
...
...
@@ -175,7 +175,7 @@ class BasicTest(TestCase):
self
.
assertEqual
(
repr
(
exc
),
'''BadStatusLine("
\
'
\
'
",)'''
)
def
test_partial_reads
(
self
):
# if we have a leng
ht
, the system knows when to close itself
# if we have a leng
th
, the system knows when to close itself
# same behaviour than when we read the whole thing with read()
body
=
"HTTP/1.1 200 Ok
\
r
\
n
Content-Length: 4
\
r
\
n
\
r
\
n
Text"
sock
=
FakeSocket
(
body
)
...
...
@@ -187,7 +187,7 @@ class BasicTest(TestCase):
self
.
assertTrue
(
resp
.
isclosed
())
def
test_partial_readintos
(
self
):
# if we have a leng
ht
, the system knows when to close itself
# if we have a leng
th
, the system knows when to close itself
# same behaviour than when we read the whole thing with read()
body
=
"HTTP/1.1 200 Ok
\
r
\
n
Content-Length: 4
\
r
\
n
\
r
\
n
Text"
sock
=
FakeSocket
(
body
)
...
...
@@ -203,6 +203,38 @@ class BasicTest(TestCase):
self
.
assertEqual
(
bytes
(
b
),
b'xt'
)
self
.
assertTrue
(
resp
.
isclosed
())
def
test_partial_reads_no_content_length
(
self
):
# when no length is present, the socket should be gracefully closed when
# all data was read
body
=
"HTTP/1.1 200 Ok
\
r
\
n
\
r
\
n
Text"
sock
=
FakeSocket
(
body
)
resp
=
client
.
HTTPResponse
(
sock
)
resp
.
begin
()
self
.
assertEqual
(
resp
.
read
(
2
),
b'Te'
)
self
.
assertFalse
(
resp
.
isclosed
())
self
.
assertEqual
(
resp
.
read
(
2
),
b'xt'
)
self
.
assertEqual
(
resp
.
read
(
1
),
b''
)
self
.
assertTrue
(
resp
.
isclosed
())
def
test_partial_readintos_no_content_length
(
self
):
# when no length is present, the socket should be gracefully closed when
# all data was read
body
=
"HTTP/1.1 200 Ok
\
r
\
n
\
r
\
n
Text"
sock
=
FakeSocket
(
body
)
resp
=
client
.
HTTPResponse
(
sock
)
resp
.
begin
()
b
=
bytearray
(
2
)
n
=
resp
.
readinto
(
b
)
self
.
assertEqual
(
n
,
2
)
self
.
assertEqual
(
bytes
(
b
),
b'Te'
)
self
.
assertFalse
(
resp
.
isclosed
())
n
=
resp
.
readinto
(
b
)
self
.
assertEqual
(
n
,
2
)
self
.
assertEqual
(
bytes
(
b
),
b'xt'
)
n
=
resp
.
readinto
(
b
)
self
.
assertEqual
(
n
,
0
)
self
.
assertTrue
(
resp
.
isclosed
())
def
test_host_port
(
self
):
# Check invalid host_port
...
...
Misc/ACKS
View file @
9b7f1b22
...
...
@@ -1022,6 +1022,7 @@ Paul Rubin
Sam Ruby
Demur Rumed
Audun S. Runde
Eran Rundstein
Rauli Ruohonen
Jeff Rush
Sam Rushing
...
...
Misc/NEWS
View file @
9b7f1b22
...
...
@@ -167,6 +167,10 @@ Core and Builtins
Library
-------
- Issue #16298: In HTTPResponse.read(), close the socket when there is no
Content-Length and the incoming stream is finished. Patch by Eran
Rundstein.
- Add abc.ABC class to use inheritance rather than a direct invocation of
ABCMeta metaclass. Patch by Bruno Dupuis.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment