1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-24 06:59:52 +01:00

statusandheaders: make protocol check case-insensitive, eg. accept HTTP/1.0 and http/1.0 for better compatibility

This commit is contained in:
Ilya Kreymer 2015-03-07 11:37:06 -08:00
parent 5aa497dc68
commit 499e21233e
2 changed files with 15 additions and 2 deletions

View File

@ -204,10 +204,11 @@ class StatusAndHeadersParser(object):
split key string into prefix and remainder split key string into prefix and remainder
for first matching prefix from a list for first matching prefix from a list
""" """
key_upper = key.upper()
for prefix in prefixs: for prefix in prefixs:
if key.startswith(prefix): if key_upper.startswith(prefix):
plen = len(prefix) plen = len(prefix)
return (key[:plen], key[plen:]) return (key_upper[:plen], key[plen:])
#================================================================= #=================================================================

View File

@ -43,6 +43,10 @@ StatusAndHeaders(protocol = '', statusline = '204 No Content', headers = [])
>>> StatusAndHeadersParser(['HTTP/1.0']).parse(BytesIO(status_headers_3)) >>> StatusAndHeadersParser(['HTTP/1.0']).parse(BytesIO(status_headers_3))
StatusAndHeaders(protocol = 'HTTP/1.0', statusline = '204 Empty', headers = [('Content-Type', 'Value'), ('Content-Length', '0')]) StatusAndHeaders(protocol = 'HTTP/1.0', statusline = '204 Empty', headers = [('Content-Type', 'Value'), ('Content-Length', '0')])
# case-insensitive match
>>> StatusAndHeadersParser(['HTTP/1.0']).parse(BytesIO(status_headers_4))
StatusAndHeaders(protocol = 'HTTP/1.0', statusline = '204 empty', headers = [('Content-Type', 'Value'), ('Content-Length', '0')])
""" """
@ -74,6 +78,14 @@ Content-Type: Value\r\n\
Content-Length: 0\r\n\ Content-Length: 0\r\n\
\r\n" \r\n"
status_headers_4 = "\
http/1.0 204 empty\r\n\
Content-Type: Value\r\n\
%Invalid%\r\n\
\tMultiline\r\n\
Content-Length: 0\r\n\
\r\n"
if __name__ == "__main__": if __name__ == "__main__":
import doctest import doctest