From 77d6bfdbc682db860d48c0df51bba58ddebdb768 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 315146adb9d6cc..20bcd6eeda1d7e 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -979,6 +979,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])`