From a63fa963b7bd01f1b470bea7c5a2ed326ff760e6 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sat, 29 Aug 2026 19:39:35 +0200 Subject: 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 --- docs/socket.html | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'docs') 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.

-You can obtain the headers namespace if case run-time -modifications are required by running: +If a lowercase field name is not present as a key, +socket.headers.canonic automatically derives a +capitalization by uppercasing the first letter of each +hyphen-separated word (e.g. x-request-id becomes +X-Request-Id), and caches the result for later lookups. +A small set of headers whose canonic capitalization is +irregular (such as ETag, Content-MD5, +MIME-Version and WWW-Authenticate) are kept as +explicit entries in the table and are not affected by this rule. +Because of this, pairs(socket.headers.canonic) only +shows the irregular entries plus any field name already looked +up or added — it is not an exhaustive list of every header +name the library knows how to capitalize. +

+ +

+You can register a custom canonic capitalization — for a +header the automatic rule would not reproduce, such as a custom +all-caps acronym — with socket.headers.setcanonic:

 -- loads the headers module
-local headers = require("headers")
+local headers = require("socket.headers")
+
+-- register a custom capitalization
+headers.setcanonic("X-Request-ID")
 
-- cgit v1.2.3-55-g6feb