Skip to main content
Http2ServerResponse.prototype.setHeader - node__http2.d.ts - Node documentation
method Http2ServerResponse.prototype.setHeader

Usage in Deno

```typescript import { Http2ServerResponse } from "node:node__http2.d.ts"; ```
Http2ServerResponse.prototype.setHeader(
name: string,
value:
number
| string
| readonly string[]
,
): void
Sets a single header value for implicit headers. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same name. ```js response.setHeader('Content-Type', 'text/html; charset=utf-8'); ``` or ```js response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']); ``` Attempting to set a header field name or value that contains invalid characters will result in a `TypeError` being thrown. When headers have been set with `response.setHeader()`, they will be merged with any headers passed to `response.writeHead()`, with the headers passed to `response.writeHead()` given precedence. ```js // Returns content-type = text/plain const server = http2.createServer((req, res) => { res.setHeader('Content-Type', 'text/html; charset=utf-8'); res.setHeader('X-Foo', 'bar'); res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' }); res.end('ok'); }); ```

Parameters

name: string
value:
number
| string
| readonly string[]

Return Type

void