request.getHeader(name)


读取请求头。 请求头的键名是大小写不敏感的。

返回值得类型取决于传入 request.setHeader() 的参数。 例子:

request.setHeader('content-type', 'text/html');
request.setHeader('Content-Length', Buffer.byteLength(body));
request.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
const contentType = request.getHeader('Content-Type');
// contentType 的值为 'text/html'。
const contentLength = request.getHeader('Content-Length');
// contentLength 是一个数值。
const setCookie = request.getHeader('set-cookie');
// setCookie 是一个字符串数组。

Reads out a header on the request. Note that the name is case insensitive. The type of the return value depends on the arguments provided to request.setHeader().

request.setHeader('content-type', 'text/html');
request.setHeader('Content-Length', Buffer.byteLength(body));
request.setHeader('Cookie', ['type=ninja', 'language=javascript']);
const contentType = request.getHeader('Content-Type');
// contentType is 'text/html'
const contentLength = request.getHeader('Content-Length');
// contentLength is of type number
const cookie = request.getHeader('Cookie');
// cookie is of type string[]