From 8e5ffe154092eddc90fd2edf890e19f58a5290ab 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 315146adb9d..20bcd6eeda1 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])`