HttpProxy

http/HttpProxy~ HttpProxy

Middleware proxy between HttpAgent implementations and the Vendor.SuperAgent, providing a Promise-oriented API for sending the requests.

Constructor

new HttpProxy(superAgent, transformer, window)

Source:
Initializes the HTTP proxy.
Parameters:
Name Type Description
superAgent vendor.SuperAgent SuperAgent instance to use for sending the HTTP requests.
transformer UrlTransformer Transformer of URLs to which the requests are made.
window Window Helper for manipulating the global object (window) regardless of the client/server-side environment.

Members

_defaultHeaders :Map.<string, string>

Source:
The default HTTP headers to include with the HTTP requests, unless overridden.
Type:
  • Map.<string, string>

_superAgent :vendor.SuperAgent

Source:
SuperAgent instance to use for sending the HTTP requests, providing uniform API across both the client-side and the server-side environments.
Type:
  • vendor.SuperAgent

_transformer :UrlTransformer

Source:
Transformer of URLs to which the requests are made.
Type:
  • UrlTransformer

_window :Window

Source:
Helper for manipulating the global object (window) regardless of the client/server-side environment.
Type:
  • Window

Methods

_composeRequestParams(method, url, data, optionsopt) → {Object}

Source:
Composes an object representing the HTTP request parameters from the provided arguments.
Parameters:
Name Type Attributes Description
method string The HTTP method to use.
url string The URL to which the request should be sent.
data Object.<string, (boolean|number|string|Date)> The data to send with the request.
options Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails, The headers set request headers. The cache can be used to bypass the cache of pending and finished HTTP requests. The withCredentials that indicates whether requests should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request.
Returns:
An object representing the complete request parameters used to create and send the HTTP request.
Type
Object

_handleError(error, reject, params)

Source:
Processes an error encountered during an HTTP request. The method processes the error, constructs an object describing the request and the error, and passes the created object to the provided promise rejection callback to reject the promise representing the said HTTP request.
Parameters:
Name Type Description
error Vendor.SuperAgent.Error The encountered error. The parameter is actually an Error instance augmented with fields providing additional details (timeout, HTTP status code, etc.).
reject function Promise rejection callback to call.
params Object An object representing the complete request parameters used to create and send the HTTP request.

_handleResponse(response, resolve, reject, params)

Source:
Processes a finished HTTP request. The method determines whether the request has been completed successfuly and resolves or rejects the promise representing the request using the provided resolution and rejection callbacks accordingly.
Parameters:
Name Type Description
response Vendor.SuperAgent.Response The response object representing the server response.
resolve function Promise resolution callback to call if the request has been completed successfuly.
reject function Promise rejection callback to call if the request failed with an error.
params Object An object representing the complete request parameters used to create and send the HTTP request.

_sendRequest(request, resolve, reject, params) → {HttpProxy}

Source:
Send the provided request to the server. The method then executes either the provided promise resolution or rejection callback depending on the request outcome.
Parameters:
Name Type Description
request Vendor.SuperAgent.Request The request to send.
resolve function Promise resolution callback to call if the request completes successfully.
reject function Promise rejection callback to call if the request fails with an error.
params Object An object representing the complete request parameters used to create and send the HTTP request.
Returns:
This instance.
Type
HttpProxy

_setCredentials(request, optionsopt) → {HttpProxy}

Source:
Whether options withCredentials is set to true that indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies or authorization headers.
Parameters:
Name Type Attributes Description
request Vendor.SuperAgent.Request The request on which the HTTP headers should be set.
options Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails, The headers set request headers. The cache can be used to bypass the cache of pending and finished HTTP requests. The withCredentials that indicates whether requests should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request.
Returns:
This instance.
Type
HttpProxy

_setHeaders(request, optionsopt) → {HttpProxy}

Source:
Applies the specified options on the provided request as HTTP headers.
Parameters:
Name Type Attributes Description
request Vendor.SuperAgent.Request The request on which the HTTP headers should be set.
options Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails, The headers set request headers. The cache can be used to bypass the cache of pending and finished HTTP requests. The withCredentials that indicates whether requests should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request.
Returns:
This instance.
Type
HttpProxy

_setListeners(request, optionsopt) → {HttpProxy}

Source:
Add listeners for HTTP request.
Parameters:
Name Type Attributes Description
request Vendor.SuperAgent.Request The request on which the HTTP listeners should be set.
options Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails, The headers set request headers. The cache can be used to bypass the cache of pending and finished HTTP requests. The withCredentials that indicates whether requests should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request.
Returns:
This instance.
Type
HttpProxy

clearDefaultHeaders()

Source:
Clears all defaults headers sent with all requests.

getErrorParams(method, url, data, optionsopt, status, body) → {Object.<string, *>}

Source:
Constructs and returns an object that describes a failed HTTP requests, providing information about both the failure reported by the server and how the request has been sent to the server.
Parameters:
Name Type Attributes Description
method string The HTTP method used to make the request.
url string The URL to which the request has been made.
data Object.<string, (boolean|number|string|Date)> The data sent with the request.
options Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails, The headers set request headers. The cache can be used to bypass the cache of pending and finished HTTP requests. The withCredentials that indicates whether requests should be made using credentials such as cookies or authorization headers.
status number The HTTP response status code send by the server.
body object The body of HTTP error response (detailed information)
Returns:
An object containing both the details of the error and the request that lead to it.
Type
Object.<string, *>

haveToSetCookiesManually() → {boolean}

Source:
Returns true if the cookies have to be processed manually by setting the Cookie HTTP header on requests and parsing the Set-Cookie HTTP response header. The result of this method depends on the current application environment, the client-side usually handles cookie processing automatically, leading this method returning false. At the client-side, the method tests whether the client has cookies enabled (which results in cookies being automatically processed by the browser), and returns true or false accordingly.
Returns:
true if the cookies are not processed automatically by the environment and have to be handled manually by parsing response headers and setting request headers.
Type
boolean

request(method, url, data, optionsopt) → {Promise.<Vendor.SuperAgent.Response>}

Source:
Executes an HTTP request to the specified URL using the specified HTTP method, carrying the provided data.
Parameters:
Name Type Attributes Description
method string The HTTP method to use.
url string The URL to which the request should be made.
data Object.<string, (boolean|number|string|Date)> The data to send to the server. The data will be included as query parameters if the request method is set to GET, and as request body for any other request method.
options Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails, The headers set request headers. The cache can be used to bypass the cache of pending and finished HTTP requests. The withCredentials that indicates whether requests should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request.
Returns:
A promise that resolves to the server response. The promise rejects on failure with an error and request descriptor object instead of an Error instance.
Type
Promise.<Vendor.SuperAgent.Response>

setDefaultHeader(header, value)

Source:
Sets the specified default HTTP header. The header will be sent with all subsequent HTTP requests unless reconfigured using this method, overridden by the request options, or cleared by the clearDefaultHeaders method.
Parameters:
Name Type Description
header string The header name.
value string The header value.