FAQ about the Fetch operation

更新时间:
复制 MD 格式

Commonly asked questions about the Fetch API in EdgeRoutine (ER), covering decompression, subrequest limits, URL validation, and connection pools.

Does Fetch support decompression?

Fetch automatically decompresses responses by default. The following decompression methods are available:

  • decompress: the default method. Reads the content-encoding header in the response and uses the decompression algorithm specified by the rightmost non-Identity value. For example, in content-encoding: gzip, identity, gzip is the decompression algorithm. If this value is removed from the response header, the following scenarios occur:

    • content-encoding: identity, gzip is the original response header. After gzip is removed, the header becomes content-encoding: identity.

    • content-encoding: gzip is the original response header. After gzip is removed, only content-encoding remains.

    Note

    After the algorithm is removed from the response header, the data becomes readable, similar to when the origin server returns uncompressed data. ER supports only Gzip and throws an exception for unrecognized algorithms. Brotli may be supported in later versions.

  • fallbackIdentity: similar to decompress, but does not throw exceptions when decompression fails. Instead, ER treats the unrecognized algorithm value as Identity and passes through the data without decompression. In this case, the data may remain unreadable if it is still compressed.

  • manual: does not decompress data.

To manually set a decompression policy, use one of the following methods:

  • fetch(url, {decompress: "manual"})

  • fetch(url, {decompress: "fallbackIdentity"})

What is the maximum number of subrequests supported by Fetch?

Fetch supports a maximum of 32 subrequests. This limit applies across all contexts, including requests captured on points of presence (POPs), 3xx redirects, and Cache API calls. To request a quota increase, submit a ticket.

Can ER recognize invalid URLs?

ER does not validate URLs. If a URL contains invalid characters, ER returns an encoding error. Ensure that your URLs are properly formatted.

What is the maximum number of connections supported by a connection pool?

ER provides a connection pool for Fetch to avoid consuming all connections with TCP or SSL handshakes. By default, the pool supports up to 128 connections. When this limit is reached, the pool stops caching new connections. To increase this quota, you can request a quota increase.

Connection pools are per-user, not per-request. If no existing connection is available, ER attempts to create a new one. ER caches a connection only after the entire response body is retrieved.

The following code shows how to ensure the entire response body is consumed:

async function fetchAndIgnore(url, options) {
  let response = await fetch(url, options);
  // This method forces ER to ignore the response body and ensures that the entire response body is retrieved. 
  await response.ignore();
}