Stone.js API
    Preparing search index...

    Class representing a JsonpResponse.

    Mr. Stone evensstone@gmail.com

    Hierarchy (View Summary)

    Index
    _blueprintResolver?: () => IBlueprint
    _charset?: Encoding
    _content: unknown

    The content of the response.

    _cookieCollection: CookieCollection
    _formats?: Record<string, () => unknown>
    _headers: Headers
    _incomingEventResolver?: () => IncomingHttpEvent
    _statusCode?: number

    The status code of the response.

    _statusMessage?: string

    The status message of the response.

    metadata: Record<string, unknown>

    The metadata associated with the event.

    originalContent: unknown

    The original content of the response.

    prepared: boolean

    The prepared status of the response.

    source?: object

    The source of the event.

    timeStamp: number

    The timestamp of the event creation.

    type: string

    The type of the event.

    OUTGOING_HTTP_RESPONSE: "stonejs@outgoing_http_jsonp_response" = 'stonejs@outgoing_http_jsonp_response'
    • get blueprint(): IBlueprint

      Get the blueprint associated with the response.

      Returns IBlueprint

      The blueprint or undefined if not set.

    • get charset(): Encoding

      Get the character set encoding. Defaults to 'utf-8' if not explicitly set.

      Returns Encoding

      The character set encoding.

    • get charsetRegExp(): RegExp
      Protected

      Get the regular expression for matching charset in content type.

      Returns RegExp

      The regular expression for matching charset in content type.

    • get content(): unknown

      Gets the content of the outgoing response.

      Returns unknown

      The content of the outgoing response.

    • get etag(): string

      Get the ETag of the response.

      Returns string

      The value of the ETag header, if present.

    • get headers(): Headers

      Get the headers of the response.

      Returns Headers

      The headers of the response as a Headers object.

    • get incomingEvent(): IncomingHttpEvent

      Get the associated IncomingHttpEvent.

      Returns IncomingHttpEvent

      The associated IncomingHttpEvent.

      InternalServerError if the IncomingHttpEvent resolver is not set.

    • get isPrepared(): boolean

      Gets the prepared status of the outgoing response.

      Returns boolean

      The prepared status of the response.

    • get lastModified(): string

      Get the Last-Modified date of the response.

      Returns string

      The value of the Last-Modified header, if present.

    • get status(): number

      Get the HTTP status code.

      Returns number

      The HTTP status code.

    • get statusCode(): number

      Gets the status code of the outgoing response.

      Returns number

      The status code of the response, or undefined if not set.

    • get statusMessage(): string

      Gets the status message of the outgoing response.

      Returns string

      The status message of the response, or undefined if not set.

    • get vary(): string[]

      Get the Vary header as an array of values.

      Returns string[]

      The Vary header values split by comma, or undefined if not present.

    • Add a field to the Vary header.

      Parameters

      • field: string | string[]

        The field to add to the Vary header.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Append a value to an existing header or create a new header.

      Parameters

      • key: string

        The header name.

      • value: string

        The value to append.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Clear a specific cookie from the response.

      Parameters

      • name: string

        The name of the cookie to be cleared.

      • options: CookieOptions = {}

        Optional settings for the cookie.

      • force: boolean = false

        Whether to force the removal of the cookie, even if it doesn't exist.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Clear all cookies from the response.

      Parameters

      • force: boolean = false

        Whether to force the removal of all cookies.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Return a cloned instance.

      The metadata container is deep-copied (plain objects and arrays are recreated, special values kept by reference) so that mutating the clone's metadata — e.g. via middleware — never leaks back into the original event. This is what makes the Kernel's originalEvent snapshot a faithful pre-middleware copy.

      Returns this

      A cloned instance of the current class.

    • Generate a default ETag for the given content.

      Parameters

      • content: string

        The content to generate an ETag for.

      • encoding: Encoding

        The encoding to use.

      Returns string

      The generated ETag as a base64 string.

    • Ensure that the "Content-Type" header has a charset specified.

      Parameters

      • value: string

        The "Content-Type" header value.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Handles content negotiation based on the Accept header of the incoming request.

      Parameters

      • formats: Record<string, () => unknown>

        An object where keys are MIME types and values are functions that return the content for that MIME type.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Get data from metadata.

      Type Parameters

      • TReturn = unknown

      Parameters

      • key: string

        The key to retrieve from metadata.

      Returns TReturn

      The value associated with the key or the fallback.

    • Get data from metadata.

      Type Parameters

      • TReturn = unknown

      Parameters

      • key: string

        The key to retrieve from metadata.

      • fallback: TReturn

        The fallback value if the key is not found.

      Returns TReturn

      The value associated with the key or the fallback.

    • Get callback.

      Returns string

      The callback function name.

    • Get the hashed content using the specified encoding.

      Parameters

      • content: string

        The content to hash.

      • encoding: Encoding

        The encoding to use for hashing.

      Returns string

      The hashed content as a hexadecimal string.

    • Get a header value.

      Type Parameters

      • TReturn = string

      Parameters

      • name: string

        The header name.

      Returns TReturn

      The header value or the fallback value.

    • Get a header value.

      Type Parameters

      • TReturn = string

      Parameters

      • name: string

        The header name.

      • fallback: TReturn

        A fallback value if the header is not found.

      Returns TReturn

      The header value or the fallback value.

    • Get all header names.

      Returns string[]

      An array of all header names.

    • Get data from metadata.

      Type Parameters

      • TReturn = unknown

      Parameters

      • key: string

        The key to retrieve from metadata.

      Returns TReturn

      The value associated with the key or the fallback.

    • Get data from metadata.

      Type Parameters

      • TReturn = unknown

      Parameters

      • key: string

        The key to retrieve from metadata.

      • fallback: TReturn

        The fallback value if the key is not found.

      Returns TReturn

      The value associated with the key or the fallback.

    • Handle cache headers like ETag and Last-Modified.

      Returns this

      The current instance of the response for chaining.

    • Handles content negotiation based on the Accept header of the incoming request.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Check if a specific header exists.

      Parameters

      • key: string

        The header name to check.

      Returns boolean

      True if the header exists, false otherwise.

    • Check if the given value is equal to the specified value.

      Parameters

      • key: string

        The key to check.

      • value: unknown

        The value to compare against.

      Returns boolean

      True if the key's value is equal to the specified value, false otherwise.

    • Check if the status code represents an informational response (1xx).

      Returns boolean

      True if the status code is informational, otherwise false.

    • Check if the status code represents a successful response (2xx).

      Returns boolean

      True if the status code is successful, otherwise false.

    • Check if the status code represents a redirection response (3xx).

      Returns boolean

      True if the status code is a redirection, otherwise false.

    • Check if the status code represents a client error response (4xx).

      Returns boolean

      True if the status code is a client error, otherwise false.

    • Check if the status code represents a server error response (5xx).

      Returns boolean

      True if the status code is a server error, otherwise false.

    • Check if the response is empty.

      Returns boolean

      True if the status code indicates an empty response, otherwise false.

    • Check if the status code is an error (i.e., 4xx or 5xx).

      Returns boolean

      True if the status code is an error, otherwise false.

    • Check if the status code is 403 (Forbidden).

      Returns boolean

      True if the status code is 403, otherwise false.

    • Check if the status code falls within the specified range.

      Parameters

      • start: number

        The starting value of the range (inclusive).

      • end: number

        The ending value of the range (exclusive).

      Returns boolean

      True if the status code is within the specified range, otherwise false.

    • Check if the status code is invalid.

      Returns boolean

      True if the status code is invalid, otherwise false.

    • Check if the status code is 301 (Moved Permanently).

      Returns boolean

      True if the status code is 301, otherwise false.

    • Check if the status code is not an error (i.e., not 4xx or 5xx).

      Returns boolean

      True if the status code is not an error, otherwise false.

    • Check if the status code is 404 (Not Found).

      Returns boolean

      True if the status code is 404, otherwise false.

    • Check if the status code is 200 (OK).

      Returns boolean

      True if the status code is 200, otherwise false.

    • Check if the response is a redirect.

      Parameters

      • Optionallocation: string

        The optional location to check for redirection.

      Returns boolean

      True if the status code indicates a redirect, otherwise false.

    • Check if the status code is 205 (Reset Content).

      Returns boolean

      True if the status code is 205, otherwise false.

    • Check if the status code is 401 (Unauthorized).

      Returns boolean

      True if the status code is 401, otherwise false.

    • Check if the response is validateable.

      Returns boolean

      True if the response has Last-Modified or ETag headers, otherwise false.

    • Make JSONP response.

      Returns this

      The current instance for method chaining.

      If no callback is provided.

    • Convert the given content to a JSON string.

      Parameters

      • content: unknown

        The content to convert.

      • options: Partial<HttpJsonConfig> = {}

        Options to customize the serialization process.

      Returns string

      A JSON string representation of the content.

      InternalServerError if the content cannot be converted to JSON.

    • Prepare content-related headers such as Content-Length and ETag.

      Returns this

      The current instance of the response for chaining.

    • Prepare cookies by setting the appropriate headers.

      Returns this

      The current instance of the response for chaining.

    • Remove headers from the response.

      Parameters

      • key: string | string[]

        The header or headers to be removed.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Secure all cookies by setting the "Secure" attribute.

      Parameters

      • value: boolean = true

        Whether to set or unset the "Secure" attribute for cookies.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set the resolver for the blueprint.

      Parameters

      • resolver: () => IBlueprint

        A function that returns the blueprint.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set callback.

      Parameters

      • callback: string | string[]

        The callback function name or array of names.

      Returns this

      The current instance for method chaining.

    • Set the character set for the response.

      Parameters

      • value: string

        The character encoding to use.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set the response content. If the content should be JSON, it will be converted appropriately.

      Parameters

      • value: unknown

        The content to set.

      • options: Partial<HttpJsonConfig> = {}

        The JSON options.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set content headers such as Content-Length and ETag.

      Returns this

      The current instance of the response for chaining.

    • Set the content type of the response.

      Parameters

      • value: string

        The MIME type for the response.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

      InternalServerError if the provided MIME type is invalid.

    • Set the content type if it's not already set.

      Returns this

      The current instance of the response for chaining.

    • Set a cookie for the response.

      Parameters

      • name: string

        The name of the cookie.

      • value: unknown

        The value of the cookie.

      • options: CookieOptions = {}

        Optional settings for the cookie.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set the ETag for the response.

      Parameters

      • Optionaletag: string

        The ETag value to set.

      • weak: boolean = false

        Whether the ETag should be marked as weak.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set a single header for the response. If the header is "Content-Type," ensures charset is set appropriately.

      Parameters

      • key: string

        The header name.

      • value: string | string[]

        The value of the header.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set multiple headers for the response.

      Parameters

      • values: HeadersType

        A key-value pair of headers to be set.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set the Last-Modified header for the response.

      Parameters

      • Optionaldate: Date

        The date to set as the Last-Modified header.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Set link headers for the response.

      Parameters

      • links: Record<string, string>

        An object representing links to set.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Add data to metadata.

      Parameters

      • key: string | Record<string, unknown>

        The key or object to add to metadata.

      • Optionalvalue: unknown

        The value to associate with the key.

      Returns this

      This Event instance.

    • Set the prepared status of the response.

      Parameters

      • prepared: boolean

        The prepared status to set.

      Returns this

      This OutgoingResponse instance.

    • Set the HTTP status code of the response. Also sets a default status message if none is provided.

      Parameters

      • code: number

        The HTTP status code.

      • Optionaltext: string

        Optional status message.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

      InternalServerError if the status code is invalid.

    • Set the content type by file extension.

      Parameters

      • value: string

        The file extension.

      Returns this

      The current instance of OutgoingHttpResponse for chaining.

    • Determine if the content should be serialized as JSON.

      Parameters

      • content: unknown

        The content to check.

      Returns boolean

      True if the content should be serialized as JSON, otherwise false.

    • Convert the given value to a JSON string with optional escaping.

      Parameters

      • value: unknown

        The value to convert.

      • Optionalreplacer: (this: unknown, key: string, value: unknown) => unknown

        A function or array that alters the behavior of the stringification process.

      • Optionalspaces: string

        The number of spaces to use for pretty-printing the JSON string.

      • Optionalescape: boolean

        Whether to escape special characters.

      Returns string

      The JSON string representation of the value.

    OUTGOING_RESPONSE: string

    OUTGOING_RESPONSE Event name, fires on response to the incoming event.

    OutgoingResponse#OUTGOING_RESPONSE