apache-log-parser
apache-log-parser copied to clipboard
Parser fails to get HTTP version for HTTP 2 protocol
The parser works fine with HTTP/1.1 but fails with HTTP/2 that appears in Apache log with Protocols h2
.
Simple example (lineB
is an actual output in the Apache server log file, lineA
is used to demonstrate that it works when replacing HTTP/2 by HTTP/1.1).
from apache_log_parser import make_parser
from pprint import pprint
lineA = '''137.226.113.25 - - [31/Dec/2017:03:14:19 +0100] "GET / HTTP/1.1" 200 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0"'''
lineB = '''137.226.113.25 - - [31/Dec/2017:03:14:19 +0100] "GET / HTTP/2" 200 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0"'''
line_parser = make_parser("%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"")
dataA = line_parser(lineA)
pprint(dataA)
dataB = line_parser(lineB)
pprint(dataB)