fetch_client 1.1.2 fetch_client: ^1.1.2 copied to clipboard
Client for http package based on Fetch API, enables streamed and cancelable requests on web and more.
Fetch Client #
This package provides package:http client based on Fetch API with WASM support.
It's a drop-in solution for extensions with Manifest V3.
Features #
- WASM-ready internals.
- Cancel requests.
- Support data streaming:
- Get response as
Stream
. - Optionally send
Stream
as request body (supported only in Chromium 105+ based browsers).
- Get response as
- Get access to redirect URL and status.
- Support non-
200
responses (fetch
will only fail on network errors). - Simulate redirects responses via probe request and artificial
location
header.
Notes #
Large payload #
This modules maps keepalive
to BaseRequest.persistentConnection
which is true
by default.
Fetch spec says that maximum request size with keepalive
flag is 64KiB:
4.5. HTTP-network-or-cache fetch
8.10.5: If the sum of contentLength and inflightKeepaliveBytes is greater than 64 kibibytes, then return a network error.
Therefore if your request is larger than 64KiB (this includes some other data,
such as headers) BaseRequest.persistentConnection
will be ignored and threated as false
.
Request streaming #
Request streaming is supported only in Chromium 105+ based browsers and requires server to use HTTP/2 or HTTP/3.
See MDN compatibility chart and Chrome Developers blog for more info.