diff --git a/components/prism-http.js b/components/prism-http.js index 4f37679e35..4b8bb84db1 100644 --- a/components/prism-http.js +++ b/components/prism-http.js @@ -1,21 +1,46 @@ (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, inside: { - // HTTP Verb - 'property': /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/, - // Path or query argument - 'attr-name': /:\w+/ + // HTTP Method + 'method': { + pattern: /^[A-Z]+\b/, + alias: 'property' + }, + // Request Target e.g. http://example.com, /path/to/file + 'request-target': { + pattern: /^(\s)(?:https?:\/\/|\/)\S*(?=\s)/, + lookbehind: true, + alias: 'url' + }, + // HTTP Version + 'http-version': { + pattern: /^(\s)HTTP\/[0-9.]+/, + lookbehind: true, + alias: 'property' + }, } }, 'response-status': { - pattern: /^HTTP\/1.[01] \d.*/m, + pattern: /^HTTP\/[0-9.]+ \d+ .+/m, inside: { - // Status, e.g. 200 OK - 'property': { - pattern: /(^HTTP\/1.[01] )\d.*/i, - lookbehind: true + // HTTP Version + 'http-version': { + pattern: /^HTTP\/[0-9.]+/, + alias: 'property' + }, + // Status Code + 'status-code': { + pattern: /^(\s)\d+(?=\s)/, + lookbehind: true, + alias: 'number' + }, + // Reason Phrase + 'reason-phrase': { + pattern: /^(\s).+/, + lookbehind: true, + alias: 'string' } } }, diff --git a/components/prism-http.min.js b/components/prism-http.min.js index 5b5b842f2c..6df7aaf172 100644 --- a/components/prism-http.min.js +++ b/components/prism-http.min.js @@ -1 +1 @@ -!function(t){t.languages.http={"request-line":{pattern:/^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\s(?:https?:\/\/|\/)\S*\sHTTP\/[0-9.]+/m,inside:{property:/^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/,"attr-name":/:\w+/}},"response-status":{pattern:/^HTTP\/1.[01] \d.*/m,inside:{property:{pattern:/(^HTTP\/1.[01] )\d.*/i,lookbehind:!0}}},"header-name":{pattern:/^[\w-]+:(?=.)/m,alias:"keyword"}};var a,e,n,i=t.languages,p={"application/javascript":i.javascript,"application/json":i.json||i.javascript,"application/xml":i.xml,"text/xml":i.xml,"text/html":i.html,"text/css":i.css},r={"application/json":!0,"application/xml":!0};for(var s in p)if(p[s]){a=a||{};var T=r[s]?(void 0,n=(e=s).replace(/^[a-z]+\//,""),"(?:"+e+"|\\w+/(?:[\\w.-]+\\+)+"+n+"(?![+\\w.-]))"):s;a[s.replace(/\//g,"-")]={pattern:RegExp("(content-type:\\s*"+T+".*)(?:\\r?\\n|\\r){2}[\\s\\S]*","i"),lookbehind:!0,inside:p[s]}}a&&t.languages.insertBefore("http","header-name",a)}(Prism); \ No newline at end of file +!function(t){t.languages.http={"request-line":{pattern:/^(?:GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI|SEARCH)\s(?:https?:\/\/|\/)\S*\sHTTP\/[0-9.]+/m,inside:{method:{pattern:/^[A-Z]+\b/,alias:"property"},"request-target":{pattern:/^(\s)(?:https?:\/\/|\/)\S*(?=\s)/,lookbehind:!0,alias:"url"},"http-version":{pattern:/^(\s)HTTP\/[0-9.]+/,lookbehind:!0,alias:"property"}}},"response-status":{pattern:/^HTTP\/[0-9.]+ \d+ .+/m,inside:{"http-version":{pattern:/^HTTP\/[0-9.]+/,alias:"property"},"status-code":{pattern:/^(\s)\d+(?=\s)/,lookbehind:!0,alias:"number"},"reason-phrase":{pattern:/^(\s).+/,lookbehind:!0,alias:"string"}}},"header-name":{pattern:/^[\w-]+:(?=.)/m,alias:"keyword"}};var a,e,s,n=t.languages,r={"application/javascript":n.javascript,"application/json":n.json||n.javascript,"application/xml":n.xml,"text/xml":n.xml,"text/html":n.html,"text/css":n.css},i={"application/json":!0,"application/xml":!0};for(var p in r)if(r[p]){a=a||{};var o=i[p]?(void 0,s=(e=p).replace(/^[a-z]+\//,""),"(?:"+e+"|\\w+/(?:[\\w.-]+\\+)+"+s+"(?![+\\w.-]))"):p;a[p.replace(/\//g,"-")]={pattern:RegExp("(content-type:\\s*"+o+".*)(?:\\r?\\n|\\r){2}[\\s\\S]*","i"),lookbehind:!0,inside:r[p]}}a&&t.languages.insertBefore("http","header-name",a)}(Prism); \ No newline at end of file diff --git a/tests/languages/http/request-line_feature.test b/tests/languages/http/request-line_feature.test index b387625765..b99af72e84 100644 --- a/tests/languages/http/request-line_feature.test +++ b/tests/languages/http/request-line_feature.test @@ -1,58 +1,126 @@ -POST http://example.com HTTP/1.0 -GET http://localhost:9999/foo.html HTTP/1.1 -PUT http://www.example.com HTTP/2.0 -DELETE https://example.com HTTP/1.1 -OPTIONS https://www.example.com HTTP/1.1 -PATCH http://example.com HTTP/1.0 -TRACE http://example.com HTTP/1.0 -CONNECT http://example.com HTTP/1.0 -GET /path/to/foo.html HTTP/1.1 +GET / HTTP/1.0 GET / HTTP/1.1 +GET /path/to/file HTTP/1.1 +GET /path/to/file?a=1&b=2 HTTP/1.1 +GET http://example.com HTTP/1.1 +GET https://example.com HTTP/1.1 +GET https://example.com/ HTTP/1.1 +GET https://example.com/path/to/file?a=1&b=2 HTTP/1.1 +GET https://example.com:443/path/to/file?a=1&b=2 HTTP/1.1 +GET https://user:pass@example.com:443/path/to/file?a=1&b=2 HTTP/1.1 +HEAD / HTTP/1.1 +POST / HTTP/1.1 +PUT / HTTP/1.1 +DELETE / HTTP/1.1 +CONNECT / HTTP/1.1 +OPTIONS / HTTP/1.1 +TRACE / HTTP/1.1 +PATCH / HTTP/1.1 +PRI / HTTP/1.1 +SEARCH / HTTP/1.1 ---------------------------------------------------- [ ["request-line", [ - ["property", "POST"], - " http://example.com HTTP/1.0" + ["method", "GET"], + ["request-target", "/"], + ["http-version", "HTTP/1.0"] ]], ["request-line", [ - ["property", "GET"], - " http://localhost", - ["attr-name", ":9999"], - "/foo.html HTTP/1.1" + ["method", "GET"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] ]], ["request-line", [ - ["property", "PUT"], - " http://www.example.com HTTP/2.0" + ["method", "GET"], + ["request-target", "/path/to/file"], + ["http-version", "HTTP/1.1"] ]], ["request-line", [ - ["property", "DELETE"], - " https://example.com HTTP/1.1" + ["method", "GET"], + ["request-target", "/path/to/file?a=1&b=2"], + ["http-version", "HTTP/1.1"] ]], ["request-line", [ - ["property", "OPTIONS"], - " https://www.example.com HTTP/1.1" + ["method", "GET"], + ["request-target", "http://example.com"], + ["http-version", "HTTP/1.1"] ]], ["request-line", [ - ["property", "PATCH"], - " http://example.com HTTP/1.0" + ["method", "GET"], + ["request-target", "https://example.com"], + ["http-version", "HTTP/1.1"] ]], ["request-line", [ - ["property", "TRACE"], - " http://example.com HTTP/1.0" + ["method", "GET"], + ["request-target", "https://example.com/"], + ["http-version", "HTTP/1.1"] ]], ["request-line", [ - ["property", "CONNECT"], - " http://example.com HTTP/1.0" + ["method", "GET"], + ["request-target", "https://example.com/path/to/file?a=1&b=2"], + ["http-version", "HTTP/1.1"] ]], ["request-line", [ - ["property", "GET"], - " /path/to/foo.html HTTP/1.1" + ["method", "GET"], + ["request-target", "https://example.com:443/path/to/file?a=1&b=2"], + ["http-version", "HTTP/1.1"] ]], ["request-line", [ - ["property", "GET"], - " / HTTP/1.1" + ["method", "GET"], + ["request-target", "https://user:pass@example.com:443/path/to/file?a=1&b=2"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "HEAD"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "POST"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "PUT"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "DELETE"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "CONNECT"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "OPTIONS"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "TRACE"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "PATCH"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "PRI"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] + ]], + ["request-line", [ + ["method", "SEARCH"], + ["request-target", "/"], + ["http-version", "HTTP/1.1"] ]] ] diff --git a/tests/languages/http/response-status_feature.test b/tests/languages/http/response-status_feature.test index 7384ff2a89..c882621ba3 100644 --- a/tests/languages/http/response-status_feature.test +++ b/tests/languages/http/response-status_feature.test @@ -7,23 +7,27 @@ HTTP/1.0 418 I'm a teapot [ ["response-status", [ - "HTTP/1.0 ", - ["property", "200 OK"] + ["http-version", "HTTP/1.0"], + ["status-code", "200"], + ["reason-phrase", "OK"] ]], ["response-status", [ - "HTTP/1.1 ", - ["property", "403 Forbidden"] + ["http-version", "HTTP/1.1"], + ["status-code", "403"], + ["reason-phrase", "Forbidden"] ]], ["response-status", [ - "HTTP/1.1 ", - ["property", "404 Not Found"] + ["http-version", "HTTP/1.1"], + ["status-code", "404"], + ["reason-phrase", "Not Found"] ]], ["response-status", [ - "HTTP/1.0 ", - ["property", "418 I'm a teapot"] + ["http-version", "HTTP/1.0"], + ["status-code", "418"], + ["reason-phrase", "I'm a teapot"] ]] ] ---------------------------------------------------- -Checks for response statuses. \ No newline at end of file +Checks for response statuses.