Authenticationerror翻译( 三 )

实现一个可读的流在Tunnel响应数据服务器:
JavaScript
class SocketResponse extends Readable {constructor({ socket, responseId }) {super();this._socket = socket;this._responseId = responseId;const onResponse = (responseId, data) => {if (this._responseId === responseId) {this._socket.off(\'response\', onResponse);this._socket.off(\'request-error\', onRequestError);this.emit(\'response\', data.statusCode, data.statusMessage, data.headers);}}const onResponsePipe = (responseId, data) => {if (this._responseId === responseId) {this.push(data);}};const onResponsePipes = (responseId, data) => {if (this._responseId === responseId) {data.forEach((chunk) => {this.push(chunk);});}};const onResponsePipeError = (responseId, error) => {if (this._responseId !== responseId) {return;}this._socket.off(\'response-pipe\', onResponsePipe);this._socket.off(\'response-pipes\', onResponsePipes);this._socket.off(\'response-pipe-error\', onResponsePipeError);this._socket.off(\'response-pipe-end\', onResponsePipeEnd);this.destroy(new Error(error));};const onResponsePipeEnd = (responseId, data) => {if (this._responseId !== responseId) {return;}if (data) {this.push(data);}this._socket.off(\'response-pipe\', onResponsePipe);this._socket.off(\'response-pipes\', onResponsePipes);this._socket.off(\'response-pipe-error\', onResponsePipeError);this._socket.off(\'response-pipe-end\', onResponsePipeEnd);this.push(null);};const onRequestError = (requestId, error) => {if (requestId === this._responseId) {this._socket.off(\'request-error\', onRequestError);this._socket.off(\'response\', onResponse);this._socket.off(\'response-pipe\', onResponsePipe);this._socket.off(\'response-pipes\', onResponsePipes);this._socket.off(\'response-pipe-error\', onResponsePipeError);this._socket.off(\'response-pipe-end\', onResponsePipeEnd);this.emit(\'requestError\', error);}};this._socket.on(\'response\', onResponse);this._socket.on(\'response-pipe\', onResponsePipe);this._socket.on(\'response-pipes\', onResponsePipes);this._socket.on(\'response-pipe-error\', onResponsePipeError);this._socket.on(\'response-pipe-end\', onResponsePipeEnd);this._socket.on(\'request-error\', onRequestError);}_read(size) {}}app.use(\'/\', (req, res) => {// ... stream request to tunnel clientconst onResponse = (statusCode, statusMessage, headers) => {socketRequest.off(\'requestError\', onRequestError)res.writeHead(statusCode, statusMessage, headers);};socketResponse.once(\'requestError\', onRequestError)socketResponse.once(\'response\', onResponse);socketResponse.pipe(res);const onSocketError = () => {res.end(500);};socketResponse.once(\'error\', onSocketError);connectedSocket.once(\'close\', onSocketError)res.once(\'close\', () => {connectedSocket.off(\'close\', onSocketError);socketResponse.off(\'error\', onSocketError);});});经过所有步骤,我们已经支持将 HTTP 请求流式传输到本地计算机,并将本地服务器的响应发送到原始请求 。它是一个精简的解决方案,但在任何环境 下都稳定且易于部署。node . js
更多的如果你只是想找一个免费的固定域名的 HTTP Tunnel服务,可以尝试将 Lite HTTP Tunnel 项目部署
https://github.com/web-tunnel/lite-http-tunnel
到 与 在 Github README 中 。希望你能从这篇文章中有所收获 。

Authenticationerror翻译

文章插图
【Authenticationerror翻译】


特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。