19 declare(strict_types=1);
43 ): ResponseInterface {
45 $server_params = $request->getServerParams();
46 if (isset($server_params[
'HTTP_RANGE']) && $this->
supportPartial()) {
55 ): ResponseInterface {
56 $uri = $stream->getMetadata(
'uri');
63 $response = $response->withHeader(
65 date(
"D, j M Y H:i:s", filemtime($uri) ?: time()) .
" GMT" 76 ): ResponseInterface {
78 return $response->withBody($stream);
85 ): ResponseInterface {
89 $server_params = $request->getServerParams();
92 $byte_length = $content_length = $stream->getSize();
94 if (isset($server_params[
'HTTP_RANGE']) && preg_match(
95 '%bytes=(\d+)-(\d+)?%i',
96 (
string) $server_params[
'HTTP_RANGE'],
99 $byte_offset = (
int) $match[1];
100 if (isset($match[2])) {
101 $finish_bytes = (
int) $match[2];
102 $byte_length = $finish_bytes + 1;
104 $finish_bytes = $content_length;
106 $response = $response->withStatus(206,
'Partial Content');
107 $response = $response->withHeader(
109 "bytes {$byte_offset}-{$finish_bytes}/{$content_length}" 113 $byte_range = $byte_length - $byte_offset;
117 $buffer_size = 512 * 16;
118 $bite_pool = $byte_range;
120 $fh = $stream->detach();
122 while ($bite_pool > 0) {
123 $chunk_size_requested = min($buffer_size, $bite_pool);
124 $buffer = fread($fh, $chunk_size_requested);
125 $chunk_actual_size = strlen($buffer);
127 if ($chunk_actual_size === 0) {
128 throw new \RuntimeException(
"Chunksize became 0");
131 $bite_pool -= $chunk_actual_size;
133 $response->getBody()->write($buffer);
deliverFull(ResponseInterface $response, FileStream $stream,)
deliverPartial(RequestInterface|ServerRequestInterface $request, ResponseInterface $response, FileStream $stream,)
supportsAttachmentDelivery()
buildForStream(ServerRequestInterface $request, ResponseInterface $response, FileStream $stream,)
buildHeaders(ResponseInterface $response, FileStream $stream)
The base interface for all filesystem streams.