response.socket
添加於:v8.4.0
返回一個 Proxy
對象,該對象充當 net.Socket
(或 tls.TLSSocket
),但應用基於 HTTP/2 邏輯的 getter、setter 和方法。
destroyed
、 readable
和 writable
屬性將從 response.stream
檢索並設置。
destroy
、 emit
、 end
、 on
和 once
方法將在 response.stream
上調用。
setTimeout
方法將在 response.stream.session
上調用。
pause
,read
,resume
, 和write
將引發代碼錯誤ERR_HTTP2_NO_SOCKET_MANIPULATION
.看Http2Session
和套接字了解更多信息。
所有其他交互將直接路由到套接字。
const http2 = require('node:http2');
const server = http2.createServer((req, res) => {
const ip = req.socket.remoteAddress;
const port = req.socket.remotePort;
res.end(`Your IP address is ${ip} and your source port is ${port}.`);
}).listen(3000);
相關用法
- Node.js http.ServerResponse response.socket用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js response.setHeader()用法及代碼示例
- Node.js http2.Http2ServerResponse response.setHeader(name, value)用法及代碼示例
- Node.js http.ServerResponse response.statusMessage用法及代碼示例
- Node.js http.ServerResponse response.setHeader(name, value)用法及代碼示例
- Node.js http2.Http2ServerResponse response.statusCode用法及代碼示例
- 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)用法及代碼示例
- Node.js http.ServerResponse response.hasHeader(name)用法及代碼示例
- Node.js http.ServerResponse response.getHeader(name)用法及代碼示例
- Node.js http.ServerResponse response.getHeaders()用法及代碼示例
- Node.js response.hasHeader()用法及代碼示例
- Node.js response.getHeaders()用法及代碼示例
- Node.js http2.Http2ServerResponse response.getHeaders()用法及代碼示例
- Node.js response.writeHead()用法及代碼示例
- Node.js http2.Http2ServerResponse response.writeHead(statusCode[, statusMessage][, headers])用法及代碼示例
- Node.js response.addTrailers()用法及代碼示例
- Node.js http2.Http2ServerResponse response.getHeader(name)用法及代碼示例
- Node.js response.getHeaderNames()用法及代碼示例
- Node.js response.write()用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 response.socket。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。