diff options
| author | Caleb Maclennan <caleb@alerque.com> | 2026-08-31 11:03:24 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-31 11:03:24 +0300 |
| commit | 5afe174eeffc7f3e3b9ef80b5871237620c68415 (patch) | |
| tree | 85c8bb14a445823dc7a683a53394901523f5f16b /docs/socket.html | |
| parent | b836466de5a78e9b4f29ca6c85a2bdecd7c69da9 (diff) | |
| parent | 3dd5fb0468977c6626fe4a0ea7b95222f14da09f (diff) | |
| download | luasocket-5afe174eeffc7f3e3b9ef80b5871237620c68415.tar.gz luasocket-5afe174eeffc7f3e3b9ef80b5871237620c68415.tar.bz2 luasocket-5afe174eeffc7f3e3b9ef80b5871237620c68415.zip | |
Merge pull request #470 from lunarmodules/header-canon
feat(headers): dynamically create cononicalized headers
Diffstat (limited to 'docs/socket.html')
| -rw-r--r-- | docs/socket.html | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/docs/socket.html b/docs/socket.html index 983f1c9..570f6d5 100644 --- a/docs/socket.html +++ b/docs/socket.html | |||
| @@ -65,13 +65,33 @@ whenever the field name is sent out. | |||
| 65 | </p> | 65 | </p> |
| 66 | 66 | ||
| 67 | <p> | 67 | <p> |
| 68 | You can obtain the <tt>headers</tt> namespace if case run-time | 68 | If a lowercase field name is not present as a key, |
| 69 | modifications are required by running: | 69 | <tt>socket.headers.canonic</tt> automatically derives a |
| 70 | capitalization by uppercasing the first letter of each | ||
| 71 | hyphen-separated word (e.g. <tt>x-request-id</tt> becomes | ||
| 72 | <tt>X-Request-Id</tt>), and caches the result for later lookups. | ||
| 73 | A small set of headers whose canonic capitalization is | ||
| 74 | irregular (such as <tt>ETag</tt>, <tt>Content-MD5</tt>, | ||
| 75 | <tt>MIME-Version</tt> and <tt>WWW-Authenticate</tt>) are kept as | ||
| 76 | explicit entries in the table and are not affected by this rule. | ||
| 77 | Because of this, <tt>pairs(socket.headers.canonic)</tt> only | ||
| 78 | shows the irregular entries plus any field name already looked | ||
| 79 | up or added — it is not an exhaustive list of every header | ||
| 80 | name the library knows how to capitalize. | ||
| 81 | </p> | ||
| 82 | |||
| 83 | <p> | ||
| 84 | You can register a custom canonic capitalization — for a | ||
| 85 | header the automatic rule would not reproduce, such as a custom | ||
| 86 | all-caps acronym — with <tt>socket.headers.setcanonic</tt>: | ||
| 70 | </p> | 87 | </p> |
| 71 | 88 | ||
| 72 | <pre class="example"> | 89 | <pre class="example"> |
| 73 | -- loads the headers module | 90 | -- loads the headers module |
| 74 | local headers = require("headers") | 91 | local headers = require("socket.headers") |
| 92 | |||
| 93 | -- register a custom capitalization | ||
| 94 | headers.setcanonic("X-Request-ID") | ||
| 75 | </pre> | 95 | </pre> |
| 76 | 96 | ||
| 77 | 97 | ||
