import URLObject from "../URLObject"; import ValueCollection, { BaseCollection } from "../ValueCollection"; import { Content } from "../../types/global"; import Cookie from "../Cookie"; import RequestContext from "../../types/internal/classes/RequestContext"; import GlobalContext from "../../types/internal/classes/GlobalContext"; import { network } from "@rjweb/utils"; import Channel from "../Channel"; import Server from "../Server"; export default class Base = {}> { /** * The Request Context Object used by the server * @since 9.0.0 */ context: RequestContext; /** * The Global Context Object used by the server * @since 9.0.0 */ global: GlobalContext; /** * The Server Object that initialized this Request * @since 9.8.0 */ server: Server<{}, []>; /** * Initializes a new Instance of a Web Context * @since 7.0.0 */ constructor(context: RequestContext, server: Server); /** * Grab a Channel from either a string identifier or a Channel object * @example * ``` * const channel = ctr.$channel('channel') * * await channel.send('text', 'Ok') * * // or * * const ref = new Channel() * const channel = ctr.$channel(ref) * * await channel.send('text', 'Ok') * ``` * @since 9.8.0 */ $channel(channel: Channel | string): Channel; /** * A Collection of all Headers * @example * ``` * if (ctr.headers.has('authorization')) console.log('Authorization Header is present') * * console.log(ctr.headers.get('authorization')) // Will print undefined if not present * console.log(ctr.headers.get('authorization', 'hello')) // Will print 'hello' if not present * ``` * @since 2.0.0 */ readonly headers: ValueCollection; /** * A Collection of all Path Parameters * @example * ``` * console.log(ctr.params.get('server')) // Will print undefined if not present * ``` * @since 2.0.0 */ readonly params: BaseCollection; /** * A Collection of all Client Cookies * @example * ``` * import { Cookie } from "rjweb-server" * * if (ctr.cookies.has('theme')) console.log('Theme Cookie is present') * * console.log(ctr.cookies.get('theme')) // Will print undefined if not present * console.log(ctr.cookies.get('theme', 'light')) // Will print 'light' if not present * * ctr.cookies.set('session', new Cookie(Math.random(), { * path: '/' * })) * ``` * @since 2.0.0 */ get cookies(): ValueCollection; /** * A Collection of all URL Queries * @example * ``` * if (ctr.queries.has('user')) console.log('User Query is present') * * console.log(ctr.queries.get('user')) // Will print undefined if not present * console.log(ctr.queries.get('user', 'default')) // Will print 'default' if not present * ``` * @since 2.0.0 */ get queries(): BaseCollection; /** * A Collection of all URL Fragments * @example * ``` * if (ctr.fragments.has('user')) console.log('User Fragment is present') * * console.log(ctr.fragments.get('user')) // Will print undefined if not present * console.log(ctr.fragments.get('user', 'default')) // Will print 'default' if not present * ``` * @since 7.0.0 */ get fragments(): BaseCollection; /** Client Infos */ readonly client: { /** * The User Agent of the Client * @since 3.0.0 */ readonly userAgent: string; /** * The Port that the Client is using * @since 3.0.0 */ readonly port: number; /** * Whether the Client IP Address is proxied * @since 9.3.0 */ readonly proxied: boolean; /** * Whether the Client IP Address is from an internal fetch * @since 9.3.0 */ readonly internal: boolean; /** * The Origin of the Clients Request * @since 9.5.0 * @example localhost:8000 */ readonly origin: string; /** * The Referrer of the Clients Request * @since 9.5.0 * @example https://localhost:8000/me */ readonly referrer: string; /** * The IP Address that the Client is using * * When a valid Proxy Request is made (and proxy is enabled) this will be the proper IP * @since 3.0.0 */ readonly ip: network.IPAddress; }; /** * The Requested URL * @since 0.0.2 */ readonly url: URLObject; /** * Context Variables that are available anywhere in the requests lifespan * @since 1.2.1 */ '@': Context; }