Skip to content

Commit 7375c2c

Browse files
committed
Ensure calling convention is followed for simple_response
1 parent 612ea8d commit 7375c2c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cheroot/server.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def parse_request(self):
809809
elif self.method == b'CONNECT':
810810
# TODO: cover this branch with tests
811811
if not self.proxy_mode:
812-
self.simple_response('405 Method Not Allowed')
812+
self.simple_response(405)
813813
return False
814814

815815
# `urlsplit()` above parses "example.com:3128" as path part of URI.
@@ -833,7 +833,7 @@ def parse_request(self):
833833
)
834834
if invalid_path:
835835
self.simple_response(
836-
'400 Bad Request',
836+
400,
837837
'Invalid path in Request-URI: request-'
838838
'target must match authority-form.',
839839
)
@@ -852,7 +852,7 @@ def parse_request(self):
852852
# (absolute form)
853853
"""Absolute URI is only allowed within proxies."""
854854
self.simple_response(
855-
'400 Bad Request',
855+
400,
856856
'Absolute URI not allowed if server is not a proxy.',
857857
)
858858
return False
@@ -871,7 +871,7 @@ def parse_request(self):
871871
'origin-form which starts with absolute-path (URI '
872872
'starting with a slash "/").'
873873
)
874-
self.simple_response('400 Bad Request', resp)
874+
self.simple_response(400, resp)
875875
return False
876876
try:
877877
# TODO: Figure out whether exception can really happen here.
@@ -962,8 +962,10 @@ def respond(self):
962962
# close connection if reuse unavailable
963963
self.close_connection = True
964964

965-
def simple_response(self, status, msg=''):
965+
def simple_response(self, status, msg=None):
966966
"""Write a simple response back to the client."""
967+
if msg is None:
968+
msg = ''
967969
status = str(status)
968970
headers = [
969971
('Content-Type', 'text/plain')

0 commit comments

Comments
 (0)