fastify-uws
Version:
A performant HTTP and WebSocket server for Fastify with uWebSockets.
63 lines (62 loc) • 1.51 kB
JavaScript
import { Readable as d } from "streamx";
import { kReq as r, kUrl as i, kHeaders as o } from "./symbols.js";
const n = () => {
};
function u() {
this.emit("aborted");
}
class y extends d {
socket;
method;
httpVersion;
readableEnded;
[r];
[i];
[o];
constructor(t, e, s) {
super(), this.socket = e, this.method = s, this.httpVersion = "1.1", this.readableEnded = !1, this[r] = t, this[i] = null, this[o] = null, this.once("error", n);
const h = super.destroy.bind(this);
e.once("error", h), e.once("close", h), e.once("aborted", u.bind(this));
}
get aborted() {
return this.socket.aborted;
}
get url() {
let t = this[i];
if (t) return t;
const e = this[r].getQuery();
return t = this[i] = this[r].getUrl() + (e && e.length > 0 ? `?${e}` : ""), t;
}
set url(t) {
this[i] = t;
}
get headers() {
let t = this[o];
return t || (t = this[o] = {}, this[r].forEach((e, s) => {
t[e] = s;
}), 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, s) => {
if (e) return t(e);
if (this.destroyed || this.destroying) return t();
this.push(s), s || (this.readableEnded = !0, t());
});
}
}
export {
y as Request
};