From dfc2dc8b6565da78d493c44aa836482dd422aeed Mon Sep 17 00:00:00 2001 From: Shogun Date: Wed, 6 Apr 2022 11:41:00 +0200 Subject: [PATCH] doc: add note about header values encoding PR-URL: https://github.com/nodejs/node/pull/42624 Fixes: https://github.com/nodejs/node/issues/42579 Co-authored-by: Antoine du Hamel Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel --- doc/api/http.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/api/http.md b/doc/api/http.md index 86234e2fef8b66..d551b588c8f22e 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -987,6 +987,17 @@ or request.setHeader('Cookie', ['type=ninja', 'language=javascript']); ``` +When the value is a string an exception will be thrown if it contains +characters outside the `latin1` encoding. + +If you need to pass UTF-8 characters in the value please encode the value +using the [RFC 8187][] standard. + +```js +const filename = 'Rock 🎵.txt'; +request.setHeader('Content-Disposition', `attachment; filename*=utf-8''${encodeURIComponent(filename)}`); +``` + ### `request.setNoDelay([noDelay])`