RequestHook.onRequest Method

Handles the request before it is sent.

class MyRequestHook extends RequestHook {
    async onRequest (event) {
        // ...
    }
}

The onRequest method's event object exposes the following fields.

Property Type Description
event.requestOptions RequestOptions Contains the request parameters. You can use it to change the request parameters before the request is sent.
event.isAjax Boolean Specifies if the request is performed using AJAX.
async onRequest (event) {
    if(event.isAjax) {
        console.log(event.requestOptions.url);
        console.log(event.requestOptions.credentials.username);

        event.requestOptions.headers['custom-header'] = 'value';
    }
}

RequestOptions

The RequestOptions object contains the request parameters.

Property Type Description
headers Object The request headers in the property-value form.
body Buffer The request body.
url String The URL to which the request is sent.
protocol String The protocol to use. Default: http:.
hostname String The alias for the host.
host String The domain name or IP address of the server to issue the request to. Default: localhost.
port Number The port of the remote server. Default: 80.
path String The request path. Should include query string if any. E.G. '/index.html?page=12'. An exception is thrown when the request path contains illegal characters. Currently, only spaces are rejected but that may change in the future. Default: '/'.
method String The string specifying the HTTP request method. Default: 'GET'.
credentials Object Credentials that were used for authentication in the current session using NTLM or Basic authentication. For HTTP Basic authentication, these are username and password. NTLM authentication additionally specifies workstation and domain. See HTTP Authentication.
proxy Object If a proxy is used, the property contains information about its host, hostname, port, proxyAuth, authHeader and bypassRules.