From 3e8d43d165ef9d363d18d1d6585582fc2742fb64 Mon Sep 17 00:00:00 2001 From: Brian White Date: Sat, 14 Jan 2017 09:39:58 -0500 Subject: [PATCH] http: add new functions to OutgoingMessage PR-URL: https://github.com/nodejs/node/pull/11562 Backport-of: https://github.com/nodejs/node/pull/10805 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig Reviewed-By: Roman Reiss Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Sam Roberts --- doc/api/http.md | 60 ++++++++++++++++++++++ lib/_http_outgoing.js | 35 +++++++++++++ test/parallel/test-http-mutable-headers.js | 46 ++++++++++++++++- 3 files changed, 140 insertions(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index 468b20a635..9698479c6f 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -948,6 +948,66 @@ Example: var contentType = response.getHeader('content-type'); ``` +### response.getHeaderNames() + + +* Returns: {Array} + +Returns an array containing the unique names of the current outgoing headers. +All header names are lowercase. + +Example: + +```js +response.setHeader('Foo', 'bar'); +response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']); + +var headerNames = response.getHeaderNames(); +// headerNames === ['foo', 'set-cookie'] +``` + +### response.getHeaders() + + +* Returns: {Object} + +Returns a shallow copy of the current outgoing headers. Since a shallow copy +is used, array values may be mutated without additional calls to various +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. + +Example: + +```js +response.setHeader('Foo', 'bar'); +response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']); + +var headers = response.getHeaders(); +// headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] } +``` + +### response.hasHeader(name) + + +* `name` {String} +* Returns: {Boolean} + +Returns `true` if the header identified by `name` is currently set in the +outgoing headers. Note that the header name matching is case-insensitive. + +Example: + +```js +var hasContentType = response.hasHeader('content-type'); +``` + ### response.headersSent