request.headers
添加於:v8.4.0
請求/響應標頭對象。
標頭名稱和值的鍵值對。標題名稱是lower-cased。
// Prints something like:
//
// { 'user-agent': 'curl/7.22.0',
// host: '127.0.0.1:8000',
// accept: '*/*' }
console.log(request.headers);
在 HTTP/2 中,請求路徑、主機名、協議和方法表示為帶有 :
字符前綴的特殊標頭(例如 ':path'
)。這些特殊標頭將包含在request.headers
對象中。必須注意不要無意中修改了這些特殊的標頭,否則可能會發生錯誤。例如,從請求中刪除所有標頭將導致錯誤發生:
removeAllHeaders(request.headers);
assert(request.url); // Fails because the :path header has been removed
相關用法
- Node.js http.ClientRequest request.hasHeader(name)用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js http.ClientRequest request.getHeaders()用法及代碼示例
- Node.js http.ClientRequest request.setHeader(name, value)用法及代碼示例
- Node.js request.writableEnded用法及代碼示例
- Node.js http.ClientRequest request.getHeaderNames()用法及代碼示例
- Node.js http.ClientRequest request.removeHeader(name)用法及代碼示例
- Node.js http.ClientRequest request.getHeader(name)用法及代碼示例
- Node.js http.ClientRequest request.reusedSocket用法及代碼示例
- Node.js http2.Http2ServerRequest request.rawHeaders用法及代碼示例
- Node.js http.ClientRequest request.getRawHeaderNames()用法及代碼示例
- Node.js http.ClientRequest request.socket用法及代碼示例
- Node.js require.cache用法及代碼示例
- Node.js require.main用法及代碼示例
- Node.js require.extensions用法及代碼示例
- Node.js require(id)用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js readStream.isRaw用法及代碼示例
- Node.js response.writeContinue()用法及代碼示例
- Node.js http2.Http2ServerResponse response.removeHeader(name)用法及代碼示例
- Node.js response.removeHeader()用法及代碼示例
- Node.js http.ServerResponse response.getHeaderNames()用法及代碼示例
- Node.js http2.Http2ServerResponse response.hasHeader(name)用法及代碼示例
- Node.js http.ServerResponse response.removeHeader(name)用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 request.headers。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。