A class that represents an HTTP request from a client.

Hierarchy

Implements

Constructors

Properties

The origin IP address of the request.

blueprintSubscribers: Collection<Unsubscribe> = ...

Collection of subscriptions to ContainerBlueprint events. We keep this around so we can remove the subscriptions when the container is destroyed.

bypassTimeout: boolean = false

If true, the response lifecycle will not time out and send errors.

clientRequest: IncomingMessage

The native Node.js request.

cookies: HTTPCookieJar

The cookie manager for the request.

factories: Collection<AbstractFactory<unknown>> = ...

Collection of factories registered with this container.

fullUrl: string

The fully-qualified URL of the request.

instances: Collection<InstanceRef> = ...

Collection of singleton instances produced by this container.

isXHR: boolean

True if the request was made via XMLHttpRequest.

mediaTypes: string[]

The media types accepted by the client.

method: HTTPMethod

The HTTP verb of the request.

parsedInput: {
    [key: string]: any;
} = {}

Input parsed from the request

Type declaration

  • [key: string]: any
path: string

The URL path, stripped of query params.

protocol: HTTPProtocol

The request HTTP protocol version.

query: {
    [key: string]: any;
}

The inferred query data.

Type declaration

  • [key: string]: any
rawQueryData: {
    [key: string]: string | string[] | undefined;
}

The raw parsed query data from the request.

Type declaration

  • [key: string]: string | string[] | undefined
response: Response

The associated response.

secure: boolean

True if the request was made via TLS.

serverResponse?: ServerResponse

The native Node.js response.

staticOverrides: Collection<{
    base: StaticInstantiable<any>;
    override: StaticInstantiable<any>;
}> = ...

Collection of static-class overrides registered with this container.

uploadedFiles: {
    [key: string]: UniversalPath;
} = {}

Files parsed from the request.

Type declaration

url: string

The URL suffix of the request.

waitingLifecycleCallbacks: Collection<WeakRef<AwareOfContainerLifecycle>> = ...

Collection of created objects that should have lifecycle events called on them, if they still exist.

waitingResolveCallbacks: Collection<{
    callback: ((t: unknown) => unknown);
    key: any;
}> = ...

Collection of callbacks waiting for a dependency key to be resolved.

makeHistory?: Collection<any>

The 100 most recent dependency keys that were make'd. Used to help with debugging cyclic dependency errors.

makeStack?: Collection<any>

List of dependency keys currently being make'd as a reverse stack. This is used to detect dependency cycles.

realizingContainer: boolean = false

Set to true when we're realizing a container. Used to prevent infinite recursion when getContainer() is accidentally called from somewhere within the realizeContainer() call.

Methods

  • Returns true if the request accepts the given media type.

    Parameters

    • type: string

      a mimetype, or the short forms json, xml, or html

    Returns boolean

  • Protected

    Check the makeStack for duplicates and throw an error if a dependency cycle is detected. This is used to prevent infinite mutual recursion when cyclic dependencies occur.

    Returns void

  • Get the value of a header, if it exists.

    Parameters

    • name: string

    Returns undefined | string | string[]

  • Create an instance of the given target. The target can either be a DependencyKey registered with this container (in which case, the singleton value will be returned), or an instantiable class.

    If the instantiable class has the Injectable decorator, its injectable parameters will be automatically injected into the instance.

    Type Parameters

    • T

    Parameters

    • target: any
    • Rest ...parameters: any[]

    Returns T

  • Create a new instance of the dependency key using this container, ignoring any pre-existing instances in this container.

    Type Parameters

    • T

    Parameters

    • key: any
    • Rest ...parameters: any[]

    Returns T

  • Get a Promise that resolves the first time the given dependency key is resolved by the application. If it has already been resolved, the Promise will resolve immediately.

    Type Parameters

    • T

    Parameters

    • key: any

    Returns Promise<T>

  • Register the given function as a factory within the container.

    Parameters

    • name: any

      unique name to identify the factory in the container

    • producer: (() => any)

      factory to produce a value

        • (): any
        • Returns any

    Returns Request

  • Register a value as a singleton in the container. It will not be instantiated, but can be injected by its unique name.

    Type Parameters

    • T

    Parameters

    • key: any

      unique name to identify the singleton in the container

    • value: T

    Returns Request

  • Resolve the dependency key. If a singleton value for that key already exists in this container, return that value. Otherwise, use the factory and given parameters to produce and return the value.

    Parameters

    • key: any
    • Rest ...parameters: any[]

    Returns any

  • Returns the short form of the content type the client has requested.

    Returns "unknown" | "json" | "xml" | "html"

  • Execute a closure on this container, disabling parent-resolution. Effectively, the closure will have access to this container as if it were NOT a scoped container, and only contained its factories.

    Type Parameters

    • T

    Parameters

    • closure: (() => T)
        • (): T
        • Returns T

    Returns T