diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-08-29 19:39:35 +0200 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-08-29 19:43:26 +0200 |
| commit | a63fa963b7bd01f1b470bea7c5a2ed326ff760e6 (patch) | |
| tree | 5f421854e7f3de2096bdc979e99f022f3918e649 /docs/socket.html | |
| parent | 84c2bb905bda5f1fc58195171c75723b5fec6e87 (diff) | |
| download | luasocket-a63fa963b7bd01f1b470bea7c5a2ed326ff760e6.tar.gz luasocket-a63fa963b7bd01f1b470bea7c5a2ed326ff760e6.tar.bz2 luasocket-a63fa963b7bd01f1b470bea7c5a2ed326ff760e6.zip | |
feat(headers): dynamically create cononicalized headers
Instead of a static list dynamically add entries in proper casing.
Also allowing to add non-standard ones through `setcanonic`.
closes #442
fixes #440
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 | ||
