Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more detail in HTTP language #2718 #2722

Merged
merged 14 commits into from Jan 18, 2021
43 changes: 33 additions & 10 deletions components/prism-http.js
@@ -1,21 +1,44 @@
(function (Prism) {
Prism.languages.http = {
'request-line': {
pattern: /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\s(?:https?:\/\/|\/)\S*\sHTTP\/[0-9.]+/m,
pattern: /^(?:GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI|SEARCH)\s(?:https?:\/\/|\/)\S*\sHTTP\/[0-9.]+/m,
Jxck marked this conversation as resolved.
Show resolved Hide resolved
inside: {
// HTTP Verb
'property': /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/,
// Path or query argument
'attr-name': /:\w+/
// HTTP Method
'method': {
pattern: /^(?:GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI|SEARCH)\b/,
Jxck marked this conversation as resolved.
Show resolved Hide resolved
alias: 'property'
},
// Request Target e.g. http://example.com, /path/to/file
'request-target': {
Jxck marked this conversation as resolved.
Show resolved Hide resolved
pattern: /^(\s)(?:https?:\/\/|\/)\S*(?=\s)/,
lookbehind: true
},
// HTTP Version
'http-version': {
pattern: /^(\s)HTTP\/[0-9.]+/,
lookbehind: true
},
}
},
'response-status': {
pattern: /^HTTP\/1.[01] \d.*/m,
pattern: /^HTTP\/1.[01] \d+ .+/m,
inside: {
// Status, e.g. 200 OK
'property': {
pattern: /(^HTTP\/1.[01] )\d.*/i,
lookbehind: true
// HTTP Version
'http-version': {
pattern: /^HTTP\/1.[01]+/,
Jxck marked this conversation as resolved.
Show resolved Hide resolved
alias: 'property'
Jxck marked this conversation as resolved.
Show resolved Hide resolved
},
// Status Code
'status-code': {
pattern: /^(\s)\d+(?=\s)/,
lookbehind: true,
alias: 'number'
},
// Reason Phrase
'reason-phrase': {
pattern: /^(\s).+/,
lookbehind: true,
alias: 'string'
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion components/prism-http.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 50 additions & 42 deletions tests/languages/http/request-line_feature.test
Expand Up @@ -12,48 +12,56 @@ GET / HTTP/1.1
----------------------------------------------------

[
["request-line", [
["property", "POST"],
" http://example.com HTTP/1.0"
]],
["request-line", [
["property", "GET"],
" http://localhost",
["attr-name", ":9999"],
"/foo.html HTTP/1.1"
]],
["request-line", [
["property", "PUT"],
" http://www.example.com HTTP/2.0"
]],
["request-line", [
["property", "DELETE"],
" https://example.com HTTP/1.1"
]],
["request-line", [
["property", "OPTIONS"],
" https://www.example.com HTTP/1.1"
]],
["request-line", [
["property", "PATCH"],
" http://example.com HTTP/1.0"
]],
["request-line", [
["property", "TRACE"],
" http://example.com HTTP/1.0"
]],
["request-line", [
["property", "CONNECT"],
" http://example.com HTTP/1.0"
]],
["request-line", [
["property", "GET"],
" /path/to/foo.html HTTP/1.1"
]],
["request-line", [
["property", "GET"],
" / HTTP/1.1"
]]
["request-line", [
["method","POST"],
Jxck marked this conversation as resolved.
Show resolved Hide resolved
["request-target","http://example.com"],
["http-version","HTTP/1.0"]
]],
["request-line", [
["method","GET"],
["request-target","http://localhost:9999/foo.html"],
["http-version","HTTP/1.1"]
]],
["request-line", [
["method","PUT"],
["request-target","http://www.example.com"],
["http-version","HTTP/2.0"]
]],
["request-line", [
["method","DELETE"],
["request-target","https://example.com"],
["http-version","HTTP/1.1"]
]],
["request-line", [
["method","OPTIONS"],
["request-target","https://www.example.com"],
["http-version","HTTP/1.1"]
]],
["request-line", [
["method","PATCH"],
["request-target","http://example.com"],
["http-version","HTTP/1.0"]
]],
["request-line", [
["method","TRACE"],
["request-target","http://example.com"],
["http-version","HTTP/1.0"]
]],
["request-line", [
["method","CONNECT"],
["request-target","http://example.com"],
["http-version","HTTP/1.0"]
]],
["request-line", [
["method","GET"],
["request-target","/path/to/foo.html"],
["http-version","HTTP/1.1"]
]],
["request-line", [
["method","GET"],
["request-target","/"],
["http-version","HTTP/1.1"]
]]
]

----------------------------------------------------
Expand Down
38 changes: 21 additions & 17 deletions tests/languages/http/response-status_feature.test
Expand Up @@ -6,24 +6,28 @@ HTTP/1.0 418 I'm a teapot
----------------------------------------------------

[
["response-status", [
"HTTP/1.0 ",
["property", "200 OK"]
]],
["response-status", [
"HTTP/1.1 ",
["property", "403 Forbidden"]
]],
["response-status", [
"HTTP/1.1 ",
["property", "404 Not Found"]
]],
["response-status", [
"HTTP/1.0 ",
["property", "418 I'm a teapot"]
]]
["response-status", [
["http-version", "HTTP/1.0"],
["status-code", "200"],
["reason-phrase", "OK"]
]],
["response-status", [
["http-version", "HTTP/1.1"],
["status-code", "403"],
["reason-phrase", "Forbidden"]
]],
["response-status", [
["http-version", "HTTP/1.1"],
["status-code", "404"],
["reason-phrase", "Not Found"]
]],
["response-status", [
["http-version", "HTTP/1.0"],
["status-code", "418"],
["reason-phrase", "I'm a teapot"]
]]
]

----------------------------------------------------

Checks for response statuses.
Checks for response statuses.