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
50badad8
Commit
50badad8
authored
Apr 03, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26586: Simple enhancements to BaseHTTPRequestHandler by Xiang Zhang
parent
b93e4b24
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
16 deletions
+14
-16
Lib/http/server.py
Lib/http/server.py
+13
-15
Lib/test/test_httpservers.py
Lib/test/test_httpservers.py
+1
-1
No files found.
Lib/http/server.py
View file @
50badad8
...
...
@@ -137,7 +137,7 @@ class HTTPServer(socketserver.TCPServer):
def
server_bind
(
self
):
"""Override server_bind to store the server name."""
socketserver
.
TCPServer
.
server_bind
(
self
)
host
,
port
=
self
.
s
ocket
.
getsockname
()
[:
2
]
host
,
port
=
self
.
s
erver_address
[:
2
]
self
.
server_name
=
socket
.
getfqdn
(
host
)
self
.
server_port
=
port
...
...
@@ -283,12 +283,9 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
words
=
requestline
.
split
()
if
len
(
words
)
==
3
:
command
,
path
,
version
=
words
if
version
[:
5
]
!=
'HTTP/'
:
self
.
send_error
(
HTTPStatus
.
BAD_REQUEST
,
"Bad request version (%r)"
%
version
)
return
False
try
:
if
version
[:
5
]
!=
'HTTP/'
:
raise
ValueError
base_version_number
=
version
.
split
(
'/'
,
1
)[
1
]
version_number
=
base_version_number
.
split
(
"."
)
# RFC 2145 section 3.1 says there can be only one "." and
...
...
@@ -310,7 +307,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
if
version_number
>=
(
2
,
0
):
self
.
send_error
(
HTTPStatus
.
HTTP_VERSION_NOT_SUPPORTED
,
"Invalid HTTP
V
ersion (%s)"
%
base_version_number
)
"Invalid HTTP
v
ersion (%s)"
%
base_version_number
)
return
False
elif
len
(
words
)
==
2
:
command
,
path
=
words
...
...
@@ -333,10 +330,11 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
try
:
self
.
headers
=
http
.
client
.
parse_headers
(
self
.
rfile
,
_class
=
self
.
MessageClass
)
except
http
.
client
.
LineTooLong
:
except
http
.
client
.
LineTooLong
as
err
:
self
.
send_error
(
HTTPStatus
.
BAD_REQUEST
,
"Line too long"
)
HTTPStatus
.
REQUEST_HEADER_FIELDS_TOO_LARGE
,
"Line too long"
,
str
(
err
))
return
False
except
http
.
client
.
HTTPException
as
err
:
self
.
send_error
(
...
...
@@ -482,12 +480,12 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
def
send_response_only
(
self
,
code
,
message
=
None
):
"""Send the response header only."""
if
message
is
None
:
if
code
in
self
.
responses
:
message
=
self
.
responses
[
code
][
0
]
else
:
message
=
''
if
self
.
request_version
!=
'HTTP/0.9'
:
if
message
is
None
:
if
code
in
self
.
responses
:
message
=
self
.
responses
[
code
][
0
]
else
:
message
=
''
if
not
hasattr
(
self
,
'_headers_buffer'
):
self
.
_headers_buffer
=
[]
self
.
_headers_buffer
.
append
((
"%s %d %s
\
r
\
n
"
%
...
...
Lib/test/test_httpservers.py
View file @
50badad8
...
...
@@ -855,7 +855,7 @@ class BaseHTTPRequestHandlerTestCase(unittest.TestCase):
# Issue #6791: same for headers
result
=
self
.
send_typical_request
(
b'GET / HTTP/1.1
\
r
\
n
X-Foo: bar'
+
b'r'
*
65537
+
b'
\
r
\
n
\
r
\
n
'
)
self
.
assertEqual
(
result
[
0
],
b'HTTP/1.1 4
00
Line too long
\
r
\
n
'
)
self
.
assertEqual
(
result
[
0
],
b'HTTP/1.1 4
31
Line too long
\
r
\
n
'
)
self
.
assertFalse
(
self
.
handler
.
get_called
)
self
.
assertEqual
(
self
.
handler
.
requestline
,
'GET / HTTP/1.1'
)
...
...
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