HttpAgentImpl

http/HttpAgentImpl~ HttpAgentImpl

Implementation of the HttpAgent interface with internal caching of completed and ongoing HTTP requests and cookie storage.

Constructor

new HttpAgentImpl(proxy, cache, cookie, config)

Source:
Initializes the HTTP handler.
Parameters:
Name Type Description
proxy HttpProxy The low-level HTTP proxy for sending the HTTP requests.
cache Cache Cache to use for caching ongoing and completed requests.
cookie CookieStorage The cookie storage to use internally.
config Object.<string, *> Configuration of the HTTP handler for the current application environment, specifying the various default request option values and cache option values.

Members

_cache :Cache

Source:
Internal request cache, used to cache completed request results.
Type:
  • Cache

_cacheOptions :Object.<string, string>

Source:
Cache options.
Type:
  • Object.<string, string>
Source:
Cookie storage, used to keep track of cookies received from the server and send them with the subsequent requests to the server.
Type:
  • CookieStorage

_defaultRequestOptions :Object

Source:
Default request options.
Type:
  • Object

_internalCacheOfPromises :Map.<string, Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>>

Source:
Internal request cache, used to cache ongoing requests.
Type:
  • Map.<string, Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>>

_proxy :HttpProxy

Source:
HTTP proxy, used to execute the HTTP requests.
Type:
  • HttpProxy

Methods

_getCachedData(method, url, data) → (nullable) {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
Tests whether an ongoing or completed HTTP request for the specified URL and data is present in the internal cache and, if it is, the method returns a promise that resolves to the response body parsed as JSON. The method returns null if no such request is present in the cache.
Parameters:
Name Type Description
method string The HTTP method used by the request.
url string The URL to which the request was made.
data Object.<string, (boolean|number|string|Date)> The data sent to the server with the request.
Returns:
A promise that will resolve to the server response with the body parsed as JSON, or null if no such request is present in the cache.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

_getCacheKeySuffix(method, url, data) → {string}

Source:
Generates cache key suffix for an HTTP request to the specified URL with the specified data.
Parameters:
Name Type Description
method string The HTTP method used by the request.
url string The URL to which the request is sent.
data Object.<string, (boolean|number|string|Date)> The data sent with the request.
Returns:
The suffix of a cache key to use for a request to the specified URL, carrying the specified data.
Type
string

_prepareOptions(options) → {Object}

Source:
Prepares the provided request options object by filling in missing options with default values and addding extra options used internally.
Parameters:
Name Type Description
options Object 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 postProcessor is method for changing agent response before than the response is saved in cache and returned in promise.
Returns:
Request options with set filled-in default values for missing fields, and extra options used internally.
Type
Object

_proxyRejected(errorParams) → {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
Handles rejection of the HTTP request by the HTTP proxy. The method tests whether there are any remaining tries for the request, and if there are any, it attempts re-send the request. The method rejects the internal request promise if there are no tries left.
Parameters:
Name Type Description
errorParams Object.<string, *> Error parameters, containing the request url, data, method, options and other useful data.
Returns:
A promise that will either resolve to a server's response (with the body parsed as JSON) if there are any tries left and the re-tried request succeeds, or rejects with an error containing details of the cause of the request's failure.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

_proxyResolved(response) → {Object}

Source:
Handles successful completion of an HTTP request by the HTTP proxy. The method also updates the internal cookie storage with the cookies received from the server.
Parameters:
Name Type Description
response Vendor.SuperAgent.Response Server response.
Returns:
The post-processed server response.
Type
Object

_request(method, url, data, optionsopt) → {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
Sends a new HTTP request using the specified method to the specified url. The request will carry the provided data as query parameters if the HTTP method is GET, but the data will be sent as request body for any other request method.
Parameters:
Name Type Attributes Description
method string HTTP method to use.
url string The URL to which the request is sent.
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. The postProcessor is method for changing agent response before than the response is saved in cache and returned in promise.
Returns:
A promise that resolves to the response with the body parsed as JSON.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

_requestWithCheckCache(method, url, data, optionsopt) → {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
Check cache and if data isnt available then make real request.
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 postProcessor is method for changing agent response before than the response is saved in cache and returned in promise.
Returns:
A promise that resolves to the response with body parsed as JSON.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

_saveAgentResponseToCache(agentResponse)

Source:
Saves the server response to the cache to be used as the result of the next request of the same properties.
Parameters:
Name Type Description
agentResponse Object The response of the server.

_setCookiesFromResponse(agentResponse)

Source:
Sets all cookies from the Set-Cookie response header to the cookie storage.
Parameters:
Name Type Description
agentResponse Object The response of the server.

clearDefaultHeaders()

Source:

delete()

Source:

get()

Source:

getCacheKey()

Source:

patch()

Source:

post()

Source:

put()

Source:

setDefaultHeader()

Source: