Skip to content

Commit

Permalink
support http response with no reason phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
if-nil authored and alecthomas committed Apr 9, 2023
1 parent 029798b commit 3c21942
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lexers/http.go
Expand Up @@ -23,7 +23,7 @@ func httpRules() Rules {
return Rules{
"root": {
{`(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE|PATCH|CONNECT)( +)([^ ]+)( +)(HTTP)(/)([123](?:\.[01])?)(\r?\n|\Z)`, ByGroups(NameFunction, Text, NameNamespace, Text, KeywordReserved, Operator, LiteralNumber, Text), Push("headers")},
{`(HTTP)(/)([123](?:\.[01])?)( +)(\d{3})( +)([^\r\n]+)(\r?\n|\Z)`, ByGroups(KeywordReserved, Operator, LiteralNumber, Text, LiteralNumber, Text, NameException, Text), Push("headers")},
{`(HTTP)(/)([123](?:\.[01])?)( +)(\d{3})( *)([^\r\n]*)(\r?\n|\Z)`, ByGroups(KeywordReserved, Operator, LiteralNumber, Text, LiteralNumber, Text, NameException, Text), Push("headers")},
},
"headers": {
{`([^\s:]+)( *)(:)( *)([^\r\n]+)(\r?\n|\Z)`, EmitterFunc(httpHeaderBlock), nil},
Expand Down
6 changes: 6 additions & 0 deletions lexers/testdata/http.response-no-reason-phrase.actual
@@ -0,0 +1,6 @@
HTTP/1.1 304
Server: nginx
Date: Sat, 08 Apr 2023 19:25:13 GMT
Connection: keep-alive
Keep-Alive: timeout=60

28 changes: 28 additions & 0 deletions lexers/testdata/http.response-no-reason-phrase.expected
@@ -0,0 +1,28 @@
[
{"type":"KeywordReserved","value":"HTTP"},
{"type":"Operator","value":"/"},
{"type":"LiteralNumber","value":"1.1"},
{"type":"Text","value":" "},
{"type":"LiteralNumber","value":"304"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"Server"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Literal","value":"nginx"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"Date"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Literal","value":"Sat, 08 Apr 2023 19:25:13 GMT"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"Connection"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Literal","value":"keep-alive"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"Keep-Alive"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Literal","value":"timeout=60"},
{"type":"Text","value":"\n\n"}
]
6 changes: 6 additions & 0 deletions lexers/testdata/http.response.actual
@@ -0,0 +1,6 @@
HTTP/1.1 202 OK
Server: nginx
Date: Sat, 08 Apr 2023 19:25:13 GMT
Connection: keep-alive
Keep-Alive: timeout=60

30 changes: 30 additions & 0 deletions lexers/testdata/http.response.expected
@@ -0,0 +1,30 @@
[
{"type":"KeywordReserved","value":"HTTP"},
{"type":"Operator","value":"/"},
{"type":"LiteralNumber","value":"1.1"},
{"type":"Text","value":" "},
{"type":"LiteralNumber","value":"202"},
{"type":"Text","value":" "},
{"type":"NameException","value":"OK"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"Server"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Literal","value":"nginx"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"Date"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Literal","value":"Sat, 08 Apr 2023 19:25:13 GMT"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"Connection"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Literal","value":"keep-alive"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"Keep-Alive"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Literal","value":"timeout=60"},
{"type":"Text","value":"\n\n"}
]

0 comments on commit 3c21942

Please sign in to comment.