Releases: ramsey/http-range
2.0.0
Added
- Nothing.
Changed
- Update the minimum PHP version to 8.2
- Add type declarations to all properties, method parameters, and method returns
- The
$totalSize
parameters andgetTotalSize()
methods are now typed asfloat | int | string
instead ofmixed
- The
getStart()
,getEnd()
, andgetLength()
methods onUnitRangeInterface
now returnfloat | int | string
instead ofmixed
Deprecated
- Nothing.
Removed
- Nothing.
Fixed
- Nothing.
1.2.1
1.2.0
1.1.0
1.0.0
Added
ramsey/http-range provides functionality for parsing HTTP range headers for a variety of range units. Out-of-the-box, ramsey/http-range supports bytes ranges as defined in RFC 7233 § 2.1, as well as basic support for generic range units. The library provides interfaces, abstract classes, and factories, allowing creation of other range units.
Example
ramsey/http-range is designed to be used with PSR-7 RequestInterface
objects. Assuming that $request
in the following example conforms to this interface, the following example shows how to use this library to parse an HTTP Range
header.
The following HTTP request uses a Range
header to request the first 500 bytes of the resource at /image/1234
.
GET /image/1234 HTTP/1.1
Host: example.com
Range: bytes=0-499
When receiving a request like this, you can parse the Range
header using the following.
use Ramsey\Http\Range\Exception\NoRangeException;
use Ramsey\Http\Range\Range;
$filePath = '/path/to/image/1234.jpg';
$filePieces = [];
$range = new Range($request, filesize($filePath));
try {
// getRanges() always returns an iterable collection of range values,
// even if there is only one range, as is the case in this example.
foreach ($range->getUnit()->getRanges() as $rangeValue) {
$filePieces[] = file_get_contents(
$filePath,
false,
null,
$rangeValue->getStart(),
$rangeValue->getLength()
);
}
} catch (NoRangeException $e) {
// This wasn't a range request or the `Range` header was empty.
}
0.1.0-alpha
Merge pull request #2 from Cloudstek/cloudstek/doc Fix docblock issues