Skip to content

Commit

Permalink
Add support for HTTP/2 responses to HTTP lexer (#1864)
Browse files Browse the repository at this point in the history
The existing HTTP lexer parses HTTP/2 requests, but not responses marked with HTTP/2. (However, it would accept HTTP/2.0.)

There is no specification for the textual representation of HTTP/2 traffic (as far as I can tell), but some tools generate response headers with only HTTP/2, which fail to be processed correctly by Rouge without this change.
  • Loading branch information
aschmitz committed Sep 3, 2022
1 parent 4c97072 commit ccd01eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def guess_content_lexer

# response
rule %r(
(HTTPS?)(/)(\d(?:\.\d))([ ]+) # http version
(HTTPS?)(/)(\d(?:\.\d)?)([ ]+) # http version
(\d{3})([ ]+)? # status
([^\r\n]*)?(\r?\n|$) # status message
)x do
Expand Down
10 changes: 10 additions & 0 deletions spec/lexers/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@
["Literal.Number", "200"],
["Text", " "]
end

it 'lexes an empty HTTP/2 response' do
response = "HTTP/2 200 "
assert_tokens_equal response, ["Keyword", "HTTP"],
["Operator", "/"],
["Literal.Number", "2"],
["Text", " "],
["Literal.Number", "200"],
["Text", " "]
end
end

0 comments on commit ccd01eb

Please sign in to comment.