fastify-uws
Version:
A performant HTTP and WebSocket server for Fastify with uWebSockets.
68 lines (67 loc) • 1.85 kB
JavaScript
var f = Object.defineProperty;
var g = (i, s, t) => s in i ? f(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
var r = (i, s, t) => g(i, typeof s != "symbol" ? s + "" : s, t);
import { Readable as p } from "streamx";
import { kReq as h, kUrl as d, kHeaders as n } from "./symbols.js";
const m = () => {
};
function b() {
this.emit("aborted");
}
var l, a, c, y;
class q extends (y = p, c = h, a = d, l = n, y) {
constructor(t, e, o) {
super();
r(this, "socket");
r(this, "method");
r(this, "httpVersion");
r(this, "readableEnded");
r(this, c);
r(this, a);
r(this, l);
this.socket = e, this.method = o, this.httpVersion = "1.1", this.readableEnded = !1, this[h] = t, this[d] = null, this[n] = null, this.once("error", m);
const u = super.destroy.bind(this);
e.once("error", u), e.once("close", u), e.once("aborted", b.bind(this));
}
get aborted() {
return this.socket.aborted;
}
get url() {
let t = this[d];
if (t) return t;
const e = this[h].getQuery();
return t = this[d] = this[h].getUrl() + (e && e.length > 0 ? `?${e}` : ""), t;
}
set url(t) {
this[d] = t;
}
get headers() {
let t = this[n];
return t || (t = this[n] = {}, this[h].forEach((e, o) => {
t[e] = o;
}), t);
}
setEncoding(t) {
this.socket.setEncoding(t);
}
setTimeout(t) {
this.socket.setTimeout(t);
}
destroy(t) {
this.destroyed || this.destroying || this.socket.destroy(t);
}
unpipe(t) {
t.destroy();
}
_read(t) {
if (this.destroyed || this.destroying || this.socket.destroyed) return t();
this.socket.onRead((e, o) => {
if (e) return t(e);
if (this.destroyed || this.destroying) return t();
this.push(o), o || (this.readableEnded = !0, t());
});
}
}
export {
q as Request
};