- Version: 8.1.2 (but applicable to others)
- Platform: all
- Subsystem: doc, http
ServerResponse.setHeader() specifies name as string and value as string | string[].
ServerResponse.writeHead() allows an object for headers (key is header name, value is header value). All samples use string for keys and string | string[] for values - except one which uses Buffer.byteLength(body) which is a number (the sample works fine).
ServerResponse.getHeader() specifies to return a string.
Actually getHeader() returns what as passed in so it should be at least string | string[].
But as setHeader() and writeHead() actually allow any stringifyable type you get also such type back as the conversion to string happens when writing the outgoing stream not during storing the header.
Not sure here if this is worth a change; and if yes should it be in doc or code?
I would guess the same is applicable to ClientRequest.
ServerResponse.setHeader()specifies name asstringand value asstring | string[].ServerResponse.writeHead()allows an object for headers (key is header name, value is header value). All samples usestringfor keys andstring | string[]for values - except one which usesBuffer.byteLength(body)which is anumber(the sample works fine).ServerResponse.getHeader()specifies to return astring.Actually
getHeader()returns what as passed in so it should be at leaststring | string[].But as
setHeader()andwriteHead()actually allow any stringifyable type you get also such type back as the conversion tostringhappens when writing the outgoing stream not during storing the header.Not sure here if this is worth a change; and if yes should it be in doc or code?
I would guess the same is applicable to
ClientRequest.