diff --git a/src/docs/markdown/caddyfile/directives/encode.md b/src/docs/markdown/caddyfile/directives/encode.md index 29d283f..d5edbfb 100644 --- a/src/docs/markdown/caddyfile/directives/encode.md +++ b/src/docs/markdown/caddyfile/directives/encode.md @@ -29,10 +29,7 @@ encode [] { minimum_length - match { - status - header [] - } + match } ``` diff --git a/src/docs/markdown/caddyfile/directives/header.md b/src/docs/markdown/caddyfile/directives/header.md index ec47062..7c19912 100644 --- a/src/docs/markdown/caddyfile/directives/header.md +++ b/src/docs/markdown/caddyfile/directives/header.md @@ -38,14 +38,7 @@ header [] [[+|-|?|>] [|] []] { [defer] - # a match condition - match [status | header ] - - # or a match block - match { - status - header [] - } + match } ``` diff --git a/src/docs/markdown/caddyfile/directives/intercept.md b/src/docs/markdown/caddyfile/directives/intercept.md index f472bfc..a7765f2 100644 --- a/src/docs/markdown/caddyfile/directives/intercept.md +++ b/src/docs/markdown/caddyfile/directives/intercept.md @@ -18,10 +18,6 @@ window.$(function() { window.$('pre.chroma .nd:contains("@name")').first().slice(0, 3) .wrapAll('').parent() .html('@name') - window.$('pre.chroma .k:contains("replace_status")').first().next() - .html('[<matcher>]') - window.$('pre.chroma .k:contains("handle_response")').first().next() - .html('[<matcher>]') window.$('pre.chroma .k') .filter((i, el) => el.innerText === 'status') .html('status') @@ -49,19 +45,19 @@ intercept [] { header [] } - replace_status [] + replace_status [] - handle_response [] { + handle_response [] { } } ``` -- **@name** is the name of a [response matcher](/docs/caddyfile/response-matchers). As long as each response matcher has a unique name, multiple matchers can be defined. A response can be matched on the status code and presence or value of a response header. +- **@name** is a named [response matcher](/docs/caddyfile/response-matchers) block. As long as each response matcher has a unique name, multiple matchers can be defined. A response can be matched on the status code and presence or value of a response header. - **replace_status** simply changes the status code of response when matched by the given matcher. -- **handle_response** defines the route to execute when matched by the given matcher (or, if a matcher is omitted, all responses). The first matching block will be applied. Inside a `handle_response` block, any other [directives](/docs/caddyfile/directives) can be used. +- **handle_response** defines the route to execute when the original response is matched by the given response matcher. If a matcher is omitted, all responses are intercepted. When multiple `handle_response` blocks are defined, the first matching block will be applied. Inside the block, all other [directives](/docs/caddyfile/directives) can be used. Within `handle_response` routes, the following placeholders are available to pull information from the original response: diff --git a/src/docs/markdown/caddyfile/response-matchers.md b/src/docs/markdown/caddyfile/response-matchers.md index be9e11f..da8625e 100644 --- a/src/docs/markdown/caddyfile/response-matchers.md +++ b/src/docs/markdown/caddyfile/response-matchers.md @@ -35,14 +35,39 @@ These typically only appear as config inside of certain other directives, to mak ## Syntax +If a directive accepts response matchers, the usage is represented as either [] or [] in the syntax documentation. + +- The **** token can be the name of a previously declared named response matcher. For example: `@name`. +- The **** token can be the response criteria itself, without requiring prior declaration. For example: `status 200`. + +### Named + ```caddy-d @name { status header [] } ``` +If only one aspect of the response is relevant to the directive, you can put the name and the criteria on the same line: +```caddy-d +@name status +``` +### Inline + +```caddy-d +{ + status + header [] +} +``` +```caddy-d +status +``` +```caddy-d +header [] +``` ## Matchers diff --git a/src/old/resources/js/docs.js b/src/old/resources/js/docs.js index 0e6a7d1..7e7de3a 100644 --- a/src/old/resources/js/docs.js +++ b/src/old/resources/js/docs.js @@ -55,6 +55,19 @@ $(function() { let text = item.innerText.replace(//g,'>'); $(item).html('' + text + ''); }); + // Add links to [] or named matcher tokens in code blocks. + // The matcher text includes <> characters which are parsed as HTML, + // so we must use text() to change the link text. + $('pre.chroma .s:contains("")') + .add('pre.chroma .s:contains("")') + .map(function(k, /** @type { HTMLElement } */ item) { + const anchor = document.createElement("a"); + anchor.href = "/docs/caddyfile/response-matchers#syntax"; + anchor.style.color = "inherit"; + anchor.title = "Response matcher token"; + item.replaceWith(anchor); + anchor.appendChild(item); + }); // Wrap all tables in a div so we can apply overflow-x: scroll $('table').wrap('
');