Req
Req extends the native Request class with a cookie jar, improved headers, and a set of pre-resolved utilities. It is used throughout Corpus in place of the native Request — i.e Context.req.Contents
Constructor
Req accepts the same arguments as the native Request: an info argument and an optional init object. On construction, all properties are resolved eagerly.
import { C } from "@ozanarslan/corpus";
const req = new C.Req("http://localhost:3000/hello?foo=bar", {
method: "GET",
headers: { authorizaton: "something" },
});Properties
urlObject
A pre-resolved URL instance derived from the request's info. Avoids repeated new URL(req.url) calls throughout the request lifecycle. If the parsed URL has no pathname, it defaults to "/".
headers
See Headers.
cookies
A Cookies instance (cookie jar) populated by parsing the Cookie request header from a native Request or using the init. Each name=value pair in the header is extracted and added to the jar on construction.
isPreflight
A boolean that is true when the request is a CORS preflight — i.e. the method is OPTIONS and the Access-Control-Request-Method header is present.
isWebsocket
A boolean that is true when the request is a WebSocket upgrade — i.e. both the Connection: upgrade and Upgrade: websocket headers are present (checked case-insensitively).