fastify-uws
Version:
A performant HTTP and WebSocket server for Fastify with uWebSockets.
2 lines (1 loc) • 1.28 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("streamx"),t=require("./symbols.cjs"),d=()=>{};function n(){this.emit("aborted")}class h extends o.Readable{socket;method;httpVersion;readableEnded;[t.kReq];[t.kUrl];[t.kHeaders];constructor(e,s,r){super(),this.socket=s,this.method=r,this.httpVersion="1.1",this.readableEnded=!1,this[t.kReq]=e,this[t.kUrl]=null,this[t.kHeaders]=null,this.once("error",d);const i=super.destroy.bind(this);s.once("error",i),s.once("close",i),s.once("aborted",n.bind(this))}get aborted(){return this.socket.aborted}get url(){let e=this[t.kUrl];if(e)return e;const s=this[t.kReq].getQuery();return e=this[t.kUrl]=this[t.kReq].getUrl()+(s&&s.length>0?`?${s}`:""),e}set url(e){this[t.kUrl]=e}get headers(){let e=this[t.kHeaders];return e||(e=this[t.kHeaders]={},this[t.kReq].forEach((s,r)=>{e[s]=r}),e)}setEncoding(e){this.socket.setEncoding(e)}setTimeout(e){this.socket.setTimeout(e)}destroy(e){this.destroyed||this.destroying||this.socket.destroy(e)}unpipe(e){e.destroy()}_read(e){if(this.destroyed||this.destroying||this.socket.destroyed)return e();this.socket.onRead((s,r)=>{if(s)return e(s);if(this.destroyed||this.destroying)return e();this.push(r),r||(this.readableEnded=!0,e())})}}exports.Request=h;