UNPKG

1.36 kBJavaScriptView Raw
1Prism.languages.http = {
2 'request-line': {
3 pattern: /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\s(?:https?:\/\/|\/)\S+\sHTTP\/[0-9.]+/m,
4 inside: {
5 // HTTP Verb
6 property: /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/,
7 // Path or query argument
8 'attr-name': /:\w+/
9 }
10 },
11 'response-status': {
12 pattern: /^HTTP\/1.[01] \d+.*/m,
13 inside: {
14 // Status, e.g. 200 OK
15 property: {
16 pattern: /(^HTTP\/1.[01] )\d+.*/i,
17 lookbehind: true
18 }
19 }
20 },
21 // HTTP header name
22 'header-name': {
23 pattern: /^[\w-]+:(?=.)/m,
24 alias: 'keyword'
25 }
26};
27
28// Create a mapping of Content-Type headers to language definitions
29var httpLanguages = {
30 'application/json': Prism.languages.javascript,
31 'application/xml': Prism.languages.markup,
32 'text/xml': Prism.languages.markup,
33 'text/html': Prism.languages.markup
34};
35
36// Insert each content type parser that has its associated language
37// currently loaded.
38for (var contentType in httpLanguages) {
39 if (httpLanguages[contentType]) {
40 var options = {};
41 options[contentType] = {
42 pattern: new RegExp('(content-type:\\s*' + contentType + '[\\w\\W]*?)(?:\\r?\\n|\\r){2}[\\w\\W]*', 'i'),
43 lookbehind: true,
44 inside: {
45 rest: httpLanguages[contentType]
46 }
47 };
48 Prism.languages.insertBefore('http', 'header-name', options);
49 }
50}