deno.com

method OutgoingMessage.prototype.setHeaders

#OutgoingMessage.prototype.setHeaders(headers: Headers | Map<string,
number
| string
| readonly string[]
>
): this

Sets multiple header values for implicit headers. headers must be an instance of Headers or Map, if a header already exists in the to-be-sent headers, its value will be replaced.

const headers = new Headers({ foo: 'bar' });
outgoingMessage.setHeaders(headers);

or

const headers = new Map([['foo', 'bar']]);
outgoingMessage.setHeaders(headers);

When headers have been set with outgoingMessage.setHeaders(), they will be merged with any headers passed to response.writeHead(), with the headers passed to response.writeHead() given precedence.

// Returns content-type = text/plain
const server = http.createServer((req, res) => {
  const headers = new Headers({ 'Content-Type': 'text/html' });
  res.setHeaders(headers);
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('ok');
});

Parameters #

#headers: Headers | Map<string,
number
| string
| readonly string[]
>

Return Type #

this