mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +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:
parent
5aa497dc68
commit
499e21233e
@ -204,10 +204,11 @@ class StatusAndHeadersParser(object):
|
||||
split key string into prefix and remainder
|
||||
for first matching prefix from a list
|
||||
"""
|
||||
key_upper = key.upper()
|
||||
for prefix in prefixs:
|
||||
if key.startswith(prefix):
|
||||
if key_upper.startswith(prefix):
|
||||
plen = len(prefix)
|
||||
return (key[:plen], key[plen:])
|
||||
return (key_upper[:plen], key[plen:])
|
||||
|
||||
|
||||
#=================================================================
|
||||
|
@ -43,6 +43,10 @@ StatusAndHeaders(protocol = '', statusline = '204 No Content', headers = [])
|
||||
>>> StatusAndHeadersParser(['HTTP/1.0']).parse(BytesIO(status_headers_3))
|
||||
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\
|
||||
\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__":
|
||||
import doctest
|
||||
|
Loading…
x
Reference in New Issue
Block a user