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
25b8b996
Commit
25b8b996
authored
Jan 25, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simply ignore headers with no name (#19996)
Patch by Cory Benfield.
parent
d92b00e6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
1 deletion
+30
-1
Lib/httplib.py
Lib/httplib.py
+5
-0
Lib/rfc822.py
Lib/rfc822.py
+6
-1
Lib/test/test_httplib.py
Lib/test/test_httplib.py
+10
-0
Lib/test/test_rfc822.py
Lib/test/test_rfc822.py
+6
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/httplib.py
View file @
25b8b996
...
@@ -313,6 +313,11 @@ class HTTPMessage(mimetools.Message):
...
@@ -313,6 +313,11 @@ class HTTPMessage(mimetools.Message):
hlist
.
append
(
line
)
hlist
.
append
(
line
)
self
.
addheader
(
headerseen
,
line
[
len
(
headerseen
)
+
1
:].
strip
())
self
.
addheader
(
headerseen
,
line
[
len
(
headerseen
)
+
1
:].
strip
())
continue
continue
elif
headerseen
is
not
None
:
# An empty header name. These aren't allowed in HTTP, but it's
# probably a benign mistake. Don't add the header, just keep
# going.
continue
else
:
else
:
# It's not a header line; throw it back and stop here.
# It's not a header line; throw it back and stop here.
if
not
self
.
dict
:
if
not
self
.
dict
:
...
...
Lib/rfc822.py
View file @
25b8b996
...
@@ -179,6 +179,11 @@ class Message:
...
@@ -179,6 +179,11 @@ class Message:
lst
.
append
(
line
)
lst
.
append
(
line
)
self
.
dict
[
headerseen
]
=
line
[
len
(
headerseen
)
+
1
:].
strip
()
self
.
dict
[
headerseen
]
=
line
[
len
(
headerseen
)
+
1
:].
strip
()
continue
continue
elif
headerseen
is
not
None
:
# An empty header name. These aren't allowed in HTTP, but it's
# probably a benign mistake. Don't add the header, just keep
# going.
continue
else
:
else
:
# It's not a header line; throw it back and stop here.
# It's not a header line; throw it back and stop here.
if
not
self
.
dict
:
if
not
self
.
dict
:
...
@@ -202,7 +207,7 @@ class Message:
...
@@ -202,7 +207,7 @@ class Message:
data in RFC 2822-like formats with special header formats.
data in RFC 2822-like formats with special header formats.
"""
"""
i
=
line
.
find
(
':'
)
i
=
line
.
find
(
':'
)
if
i
>
0
:
if
i
>
-
1
:
return
line
[:
i
].
lower
()
return
line
[:
i
].
lower
()
return
None
return
None
...
...
Lib/test/test_httplib.py
View file @
25b8b996
...
@@ -164,6 +164,16 @@ class HeaderTests(TestCase):
...
@@ -164,6 +164,16 @@ class HeaderTests(TestCase):
conn
.
request
(
'GET'
,
'/foo'
)
conn
.
request
(
'GET'
,
'/foo'
)
self
.
assertTrue
(
sock
.
data
.
startswith
(
expected
))
self
.
assertTrue
(
sock
.
data
.
startswith
(
expected
))
def
test_malformed_headers_coped_with
(
self
):
# Issue 19996
body
=
"HTTP/1.1 200 OK
\
r
\
n
First: val
\
r
\
n
: nval
\
r
\
n
Second: val
\
r
\
n
\
r
\
n
"
sock
=
FakeSocket
(
body
)
resp
=
httplib
.
HTTPResponse
(
sock
)
resp
.
begin
()
self
.
assertEqual
(
resp
.
getheader
(
'First'
),
'val'
)
self
.
assertEqual
(
resp
.
getheader
(
'Second'
),
'val'
)
class
BasicTest
(
TestCase
):
class
BasicTest
(
TestCase
):
def
test_status_lines
(
self
):
def
test_status_lines
(
self
):
...
...
Lib/test/test_rfc822.py
View file @
25b8b996
...
@@ -248,6 +248,12 @@ A test message.
...
@@ -248,6 +248,12 @@ A test message.
eq
(
rfc822
.
quote
(
'foo
\
\
wacky"name'
),
'foo
\
\
\
\
wacky
\
\
"name'
)
eq
(
rfc822
.
quote
(
'foo
\
\
wacky"name'
),
'foo
\
\
\
\
wacky
\
\
"name'
)
eq
(
rfc822
.
unquote
(
'"foo
\
\
\
\
wacky
\
\
"name"'
),
'foo
\
\
wacky"name'
)
eq
(
rfc822
.
unquote
(
'"foo
\
\
\
\
wacky
\
\
"name"'
),
'foo
\
\
wacky"name'
)
def
test_invalid_headers
(
self
):
eq
=
self
.
assertEqual
msg
=
self
.
create_message
(
"First: val
\
n
: otherval
\
n
Second: val2
\
n
"
)
eq
(
msg
.
getheader
(
'First'
),
'val'
)
eq
(
msg
.
getheader
(
'Second'
),
'val2'
)
def
test_main
():
def
test_main
():
test_support
.
run_unittest
(
MessageTestCase
)
test_support
.
run_unittest
(
MessageTestCase
)
...
...
Misc/NEWS
View file @
25b8b996
...
@@ -15,6 +15,9 @@ Core and Builtins
...
@@ -15,6 +15,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #19996: Make :mod:`httplib` ignore headers with no name rather than
assuming the body has started.
- Issue #20188: Support Application-Layer Protocol Negotiation (ALPN) in the ssl
- Issue #20188: Support Application-Layer Protocol Negotiation (ALPN) in the ssl
module.
module.
...
...
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