Commit 80940acc authored by Amos Latteier's avatar Amos Latteier

Now medusa's http server is better about handling broken HTTP requests. It now...

Now medusa's http server is better about handling broken HTTP requests. It now tries to figure out a reasonable request, and failing that it returns a 400 error.

This patch has been submitted to Sam Rushing.
parent a5bcdcfd
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# interested in using this software in a commercial context, or in # interested in using this software in a commercial context, or in
# purchasing support, please contact the author. # purchasing support, please contact the author.
RCS_ID = '$Id: http_server.py,v 1.9 1999/08/02 17:41:21 amos Exp $' RCS_ID = '$Id: http_server.py,v 1.10 1999/08/04 01:18:23 amos Exp $'
# python modules # python modules
import os import os
...@@ -443,7 +443,21 @@ class http_channel (asynchat.async_chat): ...@@ -443,7 +443,21 @@ class http_channel (asynchat.async_chat):
# crack the request header # crack the request header
# -------------------------------------------------- # --------------------------------------------------
request = lines[0] request = lines[0]
command, uri, version = crack_request (request) try:
command, uri, version = crack_request (request)
except:
# deal with broken HTTP requests
try:
# maybe there were spaces in the URL
parts=string.split(request)
command, uri, version = crack_request(
'%s %s %s' % (parts[0], parts[1], parts[-1]))
except:
self.log_info('Bad HTTP request: %s' % request, 'error')
r = http_request (self, request,
None, None, None, join_headers(lines[1:]))
r.error(400)
return
header = join_headers (lines[1:]) header = join_headers (lines[1:])
r = http_request (self, request, command, uri, version, header) r = http_request (self, request, command, uri, version, header)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# interested in using this software in a commercial context, or in # interested in using this software in a commercial context, or in
# purchasing support, please contact the author. # purchasing support, please contact the author.
RCS_ID = '$Id: http_server.py,v 1.9 1999/08/02 17:41:21 amos Exp $' RCS_ID = '$Id: http_server.py,v 1.10 1999/08/04 01:18:23 amos Exp $'
# python modules # python modules
import os import os
...@@ -443,7 +443,21 @@ class http_channel (asynchat.async_chat): ...@@ -443,7 +443,21 @@ class http_channel (asynchat.async_chat):
# crack the request header # crack the request header
# -------------------------------------------------- # --------------------------------------------------
request = lines[0] request = lines[0]
command, uri, version = crack_request (request) try:
command, uri, version = crack_request (request)
except:
# deal with broken HTTP requests
try:
# maybe there were spaces in the URL
parts=string.split(request)
command, uri, version = crack_request(
'%s %s %s' % (parts[0], parts[1], parts[-1]))
except:
self.log_info('Bad HTTP request: %s' % request, 'error')
r = http_request (self, request,
None, None, None, join_headers(lines[1:]))
r.error(400)
return
header = join_headers (lines[1:]) header = join_headers (lines[1:])
r = http_request (self, request, command, uri, version, header) r = http_request (self, request, command, uri, version, header)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment