API

Class WebRequest

Extended version of XMLHttpRequest with support for customizations (headers, ...)

Implements

  • IWebRequest
Index
CustomRequestHeaders: { [key: string]: string } = {}

Custom HTTP Request Headers to be sent with XMLHttpRequests i.e. when loading files, where the server/service expects an Authorization header

CustomRequestModifiers: (
    (request: XMLHttpRequest, url: string) => string | void
)[] = ...

Add callback functions in this array to update all the requests before they get sent to the network

SkipRequestModificationForBabylonCDN: boolean = true

If set to true, requests to Babylon.js CDN requests will not be modified

  • get onprogress(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null

    Gets or sets a function to be called when loading progress changes

    Returns ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null

  • set onprogress(
        value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null,
    ): void

    Parameters

    • value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null

    Returns void

  • get IsCustomRequestAvailable(): boolean

    This function can be called to check if there are request modifiers for network requests

    Returns boolean

    true if there are any custom requests available

  • Get the string containing the text of a particular header's value.

    Parameters

    • name: string

      The name of the header

    Returns Nullable<string>

    The string containing the text of the given header name

  • Sets the request method, request URL

    Parameters

    • method: string

      defines the method to use (GET, POST, etc..)

    • url: string

      defines the url to connect with

    • OptionalbaseHeaders: Record<string, string>

      optional headers to include as a base before applying CustomRequestHeaders and modifiers

    Returns void

  • Initiates the request. The optional argument provides the request body. The argument is ignored if request method is GET or HEAD

    Parameters

    • Optionalbody: Document | XMLHttpRequestBodyInit | null

      defines an optional request body

    Returns void

  • Sets the value of a request header.

    Parameters

    • name: string

      The name of the header whose value is to be set

    • value: string

      The value to set as the body of the header

    Returns void

  • Performs a network request using the Fetch API when available on the platform, falling back to XMLHttpRequest. WebRequest.CustomRequestHeaders and WebRequest.CustomRequestModifiers are applied in both cases.

    For CustomRequestModifiers, a minimal proxy XHR is provided to each modifier so that calls to setRequestHeader on it are captured and forwarded to the underlying request. The URL returned by a modifier (if any) replaces the current URL before the next modifier runs.

    Parameters

    • url: string

      The URL to request.

    • options: { body?: BodyInit | null; headers?: Record<string, string>; method?: string } = {}

      Optional request options (method, headers, body).

    Returns Promise<Response>

    A Promise that resolves to a Response.