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
acc03195
Commit
acc03195
authored
Apr 03, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26586: Handle excessive header fields in http.server, by Xiang Zhang
parent
af836392
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
0 deletions
+18
-0
Lib/http/server.py
Lib/http/server.py
+7
-0
Lib/test/test_httpservers.py
Lib/test/test_httpservers.py
+7
-0
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/http/server.py
View file @
acc03195
...
...
@@ -337,6 +337,13 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
HTTPStatus
.
BAD_REQUEST
,
"Line too long"
)
return
False
except
http
.
client
.
HTTPException
as
err
:
self
.
send_error
(
HTTPStatus
.
REQUEST_HEADER_FIELDS_TOO_LARGE
,
"Too many headers"
,
str
(
err
)
)
return
False
conntype
=
self
.
headers
.
get
(
'Connection'
,
""
)
if
conntype
.
lower
()
==
'close'
:
...
...
Lib/test/test_httpservers.py
View file @
acc03195
...
...
@@ -858,6 +858,13 @@ class BaseHTTPRequestHandlerTestCase(unittest.TestCase):
self
.
assertFalse
(
self
.
handler
.
get_called
)
self
.
assertEqual
(
self
.
handler
.
requestline
,
'GET / HTTP/1.1'
)
def
test_too_many_headers
(
self
):
result
=
self
.
send_typical_request
(
b'GET / HTTP/1.1
\
r
\
n
'
+
b'X-Foo: bar
\
r
\
n
'
*
101
+
b'
\
r
\
n
'
)
self
.
assertEqual
(
result
[
0
],
b'HTTP/1.1 431 Too many headers
\
r
\
n
'
)
self
.
assertFalse
(
self
.
handler
.
get_called
)
self
.
assertEqual
(
self
.
handler
.
requestline
,
'GET / HTTP/1.1'
)
def
test_close_connection
(
self
):
# handle_one_request() should be repeatedly called until
# it sets close_connection
...
...
Misc/NEWS
View file @
acc03195
...
...
@@ -99,6 +99,10 @@ Core and Builtins
Library
-------
- Issue #26586: In http.server, respond with "413 Request header fields too
large" if there are too many header fields to parse, rather than killing
the connection and raising an unhandled exception. Patch by Xiang Zhang.
- Issue #22854: Change BufferedReader.writable() and
BufferedWriter.readable() to always return False.
...
...
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