From 3e6f1032a4fdb8ca7fba02c7d2103fba68c0ee1f 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/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 aed82481f56a6d..ea01359e1daa0b 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -934,6 +934,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