Fetching content from the web is environment-specific, so Ethers provides an abstraction that each environment can implement to provide this service.
On Node.js, the http and https libs are used to create a request object, register event listeners and process data and populate the FetchResponse.
In a browser, the DOM fetch is used, and the resulting Promise is waited on to retrieve the payload.
The FetchRequest is responsible for handling many common situations, such as redirects, server throttling, authentication, etc.
It also handles common gateways, such as IPFS and data URIs.
This can be used to control how throttling is handled in fetchRequest.setThrottleParams.
Represents a request for a resource using a URI.
By default, the supported schemes are HTTP, HTTPS, data:, and IPFS:.
Additional schemes can be added globally using registerGateway.
The fetch body, if any, to send as the request body. (default: null)
When setting a body, the intrinsic Content-Type is automatically set and will be used if not overridden by setting a custom header.
If body is null, the body is cleared (along with the intrinsic Content-Type).
If body is a string, the intrinsic Content-Type is set to text/plain.
If body is a Uint8Array, the intrinsic Content-Type is set to application/octet-stream.
If body is any other object, the intrinsic Content-Type is set to application/json.
This function is called to fetch content from HTTP and HTTPS URLs and is platform specific (e.g. nodejs vs browsers).
This is by default the currently registered global getUrl function, which can be changed using registerGetUrl. If this has been set, setting is to null will cause this FetchRequest (and any future clones) to revert back to using the currently registered global getUrl function.
Setting this is generally not necessary, but may be useful for developers that wish to intercept requests or to configurege a proxy or other agent.
This function is called after each response, offering an opportunity to provide client-level throttling or updating response data.
Any error thrown in this causes the send() to throw.
To schedule a retry attempt (assuming the maximum retry limit has not been reached), use [[response.throwThrottleError]].
Cancels the inflight response, causing a CANCELLED error to be rejected from the send.
Returns a new FetchRequest that represents the redirection to location.
Creates a getUrl function that fetches content from HTTP and HTTPS URLs.
The available options are dependent on the platform implementation of the default getUrl function.
This is not generally something that is needed, but is useful when trying to customize simple behaviour when fetching HTTP content.
Use the func when fetching URIs using scheme.
This method affects all requests globally.
If lockConfig has been called, no change is made and this throws.
Use getUrl when fetching URIs over HTTP and HTTPS requests.
This method affects all requests globally.
If lockConfig has been called, no change is made and this throws.
If called within a request.processFunc call, causes the request to retry as if throttled for stall milliseconds.