Range origin fetch is a feature that allows a DCDN point of presence (POP) to include a Range header in an HTTP request to the origin server. When the origin server receives the request from the DCDN POP, it returns the specified range of data to the DCDN POP based on the Range header. Range origin fetch can effectively improve file distribution efficiency, increase the cache hit ratio, reduce origin traffic consumption and origin server pressure, and improve resource response speed.
Background
The Range header is an HTTP header that specifies the range of content to retrieve. For example, Range: bytes=0-100 indicates that the back-to-origin request retrieves the first 101 bytes of data from the file.
After you enable the Range origin fetch feature, when DCDN receives a user request, if the resource is not cached or has expired on a DCDN point of presence (POP), the DCDN POP performs an origin fetch by using Range requests to retrieve the required part of the resource from the origin server in segments and caches it on the DCDN POP.
The following figure shows how range origin fetch works.
Usage notes
Before you enable range origin fetch, ensure that your origin server supports range requests. This means the origin server must be able to process the Range field in an HTTP header and respond with a
206 Partial Contentstatus code. If your origin server does not support range requests, enabling this feature will cause resource caching to fail.The Multipart Ranges feature is disabled by default and is not automatically enabled when you enable range origin fetch. To enable the Multipart Ranges feature, submit a ticket.
Enabling the range origin fetch feature increases the QPS for origin fetches. If rate limiting is enabled on your origin server, this may trigger its rate limiting rules. As a workaround, call the DescribeL2VipsByDomain operation to query the IP addresses of the DCDN origin fetch POPs, and add the IP addresses of the DCDN origin fetch POPs to the IP address whitelist of your origin server.
Procedure
-
Log on to the DCDN console.
-
In the left-side navigation pane, click Domain Names.
-
On the Domain Names page, find the domain name that you want to manage and click Configure.
-
In the left-side navigation tree of the domain name, click Origin Fetch.
On the Origin Fetch tab, find the Range Origin Fetch section and click Modify.
Based on the parameter descriptions in the following table, set Range Origin Fetch to Do Not Enable Range Origin Fetch, Match Client, or Enable Range Origin Fetch (Recommended for Large File Delivery).
If you select Match Client or Enable Range Origin Fetch (Recommended for Large File Delivery) for Range Origin Fetch, you can set the Shard Size. The default shard size is 512 KB.
Parameter
Option
Description
Example
Range Origin Fetch
Do Not Enable Range Origin Fetch
The default setting is Do not use range origin fetch. With this setting, regardless of whether a client sends a Range request to a DCDN point of presence (POP), the DCDN POP fetches the entire file from the origin. This results in lower file distribution efficiency for large files.
For example, if a request from a client to a DCDN POP contains
Range: bytes=0-100, the DCDN POP sends a request to the origin server without the Range parameter. The origin server sends the entire file to the DCDN POP. For example, if the file is 10 MB, the origin server sends the 10 MB file to the DCDN POP. The DCDN POP caches the file that it receives from the origin server and then responds to the client with the content for theRange: bytes=0-100request.Match Client
After you enable Follow Client Range Requests, when a client sends a Range request to a DCDN node, the DCDN node sends a Range request to the origin server. The first back-to-origin request from the DCDN node retrieves a data chunk whose size is the Range size of the client request rounded up to the nearest integer multiple of the shard size. All subsequent requests to your origin server are based on the shard size that you specify.
For example, when the shard size is 512 KB, if a client sends a request to a DCDN POP that contains
Range:bytes=0-614399(which is 600 KB), and the file is not cached on the DCDN POP, the first origin fetch retrieves a 1024 KB shard (600 KB rounded up to 1024 KB). For subsequent requests for other uncached shards of the file, the DCDN POP accesses the origin server by using a shard size of 512 KB.Enable Range Origin Fetch (Recommended for Large File Delivery)
After you enable Enable Range Origin Fetch (Recommended for large files), regardless of whether a client sends a Range request to a DCDN point of presence (POP), the DCDN POP uses Range requests for origin fetch. All origin-fetch Range requests from the DCDN POPs to the origin server use the shard size that you specify.
None
Shard Size
512 KB
1 MB
2 MB
4 MB
You can set the shard size for range origin fetch if the mode is set to Match Client or Enable Range Origin Fetch (Recommended for Large File Delivery). The default shard size is 512 KB.
1 MB
Rule Condition
A rule condition determines whether a configuration applies to a request by evaluating various parameters in the request.
ImportantWhen a feature references rule conditions configured in the rules engine, the execution order follows the priority of the associated rule conditions, not the order of the feature configurations.
Do not use conditions: Disables conditional rules.
You can add or edit conditional rules in Rules engine.
A rule condition identifies parameters in user requests to determine whether a configuration applies to a specific request.
Disable
Handling out-of-range HTTP Range requests
When fetches large files from an OSS origin server, issues may occur if the OSS server responds with a cache-control:no-cache policy or if a client request to triggers a Range-based origin fetch. These issues can manifest as abnormally slow downloads or even timeouts (after about 30 seconds), and a dropped connection when an out-of-range slice (such as the last slice of the file) is downloaded.
Behavior without a compatibility policy
If an HTTP Range request is valid, Object Storage Service (OSS) returns a
206response and includes theContent-Rangeheader. If an HTTP Range request is invalid, or if the specified range is out of bounds, the Range request is ignored. OSS returns a200response and transfers the entire object. The following examples show invalid HTTP Range requests and explain the errors.NoteThe following examples assume an object size of 1000 bytes, with a valid range of 0 to 999. To prevent the specified range from being out of bounds, send a HeadObject request to get the object size before you read the range.
Range: byte=0-499: Invalid format.byteshould bebytes.Range: bytes=0-1000: The end byte, 1000, is out of the valid range.Range: bytes=1000-2000: The specified range is out of the valid range.Range: bytes=1000-: The start byte is out of the valid range.Range: bytes=-2000: The specified range is out of the valid range.
Use the following command to test the validity of the Range parameter:
curl -r 0-100 http://xxxx.oss-cn-hangzhou.aliyuncs.com/xx.zip -o /tmp/xx1.zip -vBehavior with a compatibility policy
Add the
x-oss-range-behavior:standardheader to an HTTP Range request to change how OSS behaves when the specified range is out of bounds. The following examples show how the behavior changes:NoteThe following examples assume an object size of 1000 bytes, with a valid range of 0 to 999. If you use an HTTP Range request to get part of a large file and select an invalid range, OSS returns an InvalidRange error code. For more information about how to resolve this issue, see OSS returns a 416 error. The detailed error message is as follows:
The requested range cannot be satisfiedRange: bytes=500-2000: The end byte is out of the valid range. OSS returns the content in the byte range of 500 to 999.Range: bytes=1000-2000: The start byte is out of the valid range. OSS returns a416 (InvalidRange)error.Range: bytes=1000-: The start byte is out of the valid range. OSS returns a416 (InvalidRange)error.Range: bytes=-2000: The specified range is out of the valid range. OSS returns the content in the byte range of 0 to 999, which is the complete file.
This topic provides the following HTTP Range request examples.
NoteThe following examples assume an object size of 1000 bytes, with a valid range of 0 to 999.
Request the content of an object within the byte range of 0 to 499.
GET /ObjectName Range: bytes=0-499 Host: bucket.oss-cn-hangzhou.aliyuncs.com Date: Fri, 18 Oct 2019 02:51:30 GMT Authorization: Signature 206 (Partial Content) content-length: 500 content-range: bytes 0-499/1000 connection: keep-alive etag: "CACF99600561A31D494569C979E6FB81" x-oss-request-id: 5DA928B227D52731327DE078 date: Fri, 18 Oct 2019 02:51:30 GMT [500 bytes of object data]Request the content of an object from byte 500 to the end of the file.
GET /ObjectName Range: bytes=500- Host: bucket.oss-cn-hangzhou.aliyuncs.com Date: Fri, 18 Oct 2019 03:24:39 GMT Authorization: Signature 206 (Partial Content) content-length: 500 content-range: bytes 500-999/1000 etag: "CACF99600561A31D494569C979E6FB81" x-oss-request-id: 5DA9307750EBE33332E3720A date: Fri, 18 Oct 2019 03:24:39 GMT [500 bytes of object data]Request the last 500 bytes of an object.
GET /ObjectName Range: bytes=-500 Host: bucket.oss-cn-hangzhou.aliyuncs.com Date: Fri, 18 Oct 2019 03:23:22 GMT Authorization: Signature 206 (Partial Content) content-length: 500 content-range: bytes 500-999/1000 etag: "CACF99600561A31D494569C979E6FB81" x-oss-request-id: 5DA9302A6646AC37397F7039 date: Fri, 18 Oct 2019 03:23:22 GMT [500 bytes of object data]
For large file distribution where the average file size is more than 20 MB, configure this setting for and DCDN origin fetch to OSS.
If access authentication is enabled on your Alibaba Cloud OSS origin server and clients are responsible for signing origin fetch requests, clients must include the
x-oss-range-behavior:standardrequest header in the signature calculation. Alibaba Cloud OSS includes all request headers with thex-oss-prefix in its signature calculation. If the client's signature calculation does not include thex-oss-range-behaviorrequest header, a signature mismatch occurs and the request is rejected.