diff --git a/pywb/utils/statusandheaders.py b/pywb/utils/statusandheaders.py index 7f08cbdb..0ecfa59a 100644 --- a/pywb/utils/statusandheaders.py +++ b/pywb/utils/statusandheaders.py @@ -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:]) #================================================================= diff --git a/pywb/utils/test/test_statusandheaders.py b/pywb/utils/test/test_statusandheaders.py index 5fe96d95..8af2b50f 100644 --- a/pywb/utils/test/test_statusandheaders.py +++ b/pywb/utils/test/test_statusandheaders.py @@ -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