From 203f1f6ce6c32f292af793f74823c0a1f53cc86e Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 12 Sep 2022 21:29:30 +0200 Subject: [PATCH] doc: fix errors in http.md Fixes: https://github.com/nodejs/node/issues/44567 PR-URL: https://github.com/nodejs/node/pull/44587 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Trivikram Kamat Reviewed-By: Paolo Insogna Reviewed-By: Mestery --- doc/api/http.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index f81d970fc66..cb7b91a72f0 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -883,7 +883,7 @@ header-related http module methods. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase. -The object returned by the `response.getHeaders()` method _does not_ +The object returned by the `request.getHeaders()` method _does not_ prototypically inherit from the JavaScript `Object`. This means that typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others are not defined and _will not work_. @@ -892,7 +892,7 @@ are not defined and _will not work_. request.setHeader('Foo', 'bar'); request.setHeader('Cookie', ['foo=bar', 'bar=baz']); -const headers = response.getHeaders(); +const headers = request.getHeaders(); // headers === { foo: 'bar', 'cookie': ['foo=bar', 'bar=baz'] } ``` @@ -2336,7 +2336,7 @@ Key-value pairs of header names and values. Header names are lower-cased. // { 'user-agent': 'curl/7.22.0', // host: '127.0.0.1:8000', // accept: '*/*' } -console.log(request.getHeaders()); +console.log(request.headers); ``` Duplicates in raw headers are handled in the following ways, depending on the @@ -2535,15 +2535,15 @@ Accept: text/plain To parse the URL into its parts: ```js -new URL(request.url, `http://${request.getHeaders().host}`); +new URL(request.url, `http://${request.headers.host}`); ``` -When `request.url` is `'/status?name=ryan'` and -`request.getHeaders().host` is `'localhost:3000'`: +When `request.url` is `'/status?name=ryan'` and `request.headers.host` is +`'localhost:3000'`: ```console $ node -> new URL(request.url, `http://${request.getHeaders().host}`) +> new URL(request.url, `http://${request.headers.host}`) URL { href: 'http://localhost:3000/status?name=ryan', origin: 'http://localhost:3000',