Hi,
Some time ago, I developed a micro package called http-directives. It helps reuse common HTTP constants and reduces the chance of typos in the code. A simple thing, but it helped me uncover two issues:
import { Headers } from 'http-directives';
class ServiceHeaders extends Headers {
static readonly X_CAPTCHA_TOKEN = 'X-Captcha-Token';
}
- I passed this header,
ServiceHeaders.X_CAPTCHA_TOKEN, into CORS and middleware for captcha handling.
It turned out that request.headers doesn’t have a get method to retrieve a header value by name:
const token = request.headers[ServiceHeaders.X_CAPTCHA_TOKEN];
This doesn’t work because X-Captcha-Token is written in uppercase, while the server returns headers in lowercase.
-
There can be multiple headers with the same name.
-
The current interface is not compatible with the Headers types:
It would be great to have a unified interface for working with headers and cookies, like in Next.js and similar frameworks. That would reduce boilerplate and minimize the risk of subtle bugs.
To handle header properties, there is a popular package headers-polyfill.
Hi,
Some time ago, I developed a micro package called http-directives. It helps reuse common HTTP constants and reduces the chance of typos in the code. A simple thing, but it helped me uncover two issues:
ServiceHeaders.X_CAPTCHA_TOKEN, into CORS and middleware for captcha handling.It turned out that
request.headersdoesn’t have a get method to retrieve a header value by name:This doesn’t work because
X-Captcha-Tokenis written in uppercase, while the server returns headers in lowercase.There can be multiple headers with the same name.
The current interface is not compatible with the Headers types:
It would be great to have a unified interface for working with headers and cookies, like in Next.js and similar frameworks. That would reduce boilerplate and minimize the risk of subtle bugs.
To handle header properties, there is a popular package headers-polyfill.