diff --git a/composer.json b/composer.json index 2d1f09345..9f1774727 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "ext-fileinfo": "*", "amphp/amp": "^3", "amphp/http-client": "^5", + "amphp/http": "^2", "amphp/socket": "^2", "amphp/dns": "^2", "amphp/byte-stream": "^2", diff --git a/src/MTProtoTools/FilesLogic.php b/src/MTProtoTools/FilesLogic.php index 95048f1c9..5ccac7b0f 100644 --- a/src/MTProtoTools/FilesLogic.php +++ b/src/MTProtoTools/FilesLogic.php @@ -14,7 +14,7 @@ use Amp\File\Driver\BlockingFile; use Amp\File\File; use Amp\Http\Server\Request as ServerRequest; use Amp\Http\Server\Response; -use Amp\Http\Status; +use Amp\Http\HttpStatus; use Amp\Sync\LocalMutex; use Amp\Sync\Lock; use danog\MadelineProto\Exception; @@ -94,7 +94,7 @@ trait FilesLogic } \http_response_code($result->getCode()); - if (!\in_array($result->getCode(), [Status::OK, Status::PARTIAL_CONTENT])) { + if (!\in_array($result->getCode(), [HttpStatus::OK, HttpStatus::PARTIAL_CONTENT])) { Tools::echo($result->getCodeExplanation()); } elseif ($result->shouldServe()) { if (!empty($messageMedia['name']) && !empty($messageMedia['ext'])) { @@ -198,13 +198,13 @@ trait FilesLogic $pipe = new Pipe(1024 * 1024); EventLoop::queue($this->downloadToStream(...), $messageMedia, $pipe->getSink(), $cb, ...$result->getServeRange()); $body = $pipe->getSource(); - } elseif (!\in_array($result->getCode(), [Status::OK, Status::PARTIAL_CONTENT])) { + } elseif (!\in_array($result->getCode(), [HttpStatus::OK, HttpStatus::PARTIAL_CONTENT])) { $body = $result->getCodeExplanation(); } $response = new Response($result->getCode(), $result->getHeaders(), $body); if ($result->shouldServe() && !empty($result->getHeaders()['Content-Length'])) { - $response->setHeader('content-length', $result->getHeaders()['Content-Length']); + $response->setHeader('content-length', (string)$result->getHeaders()['Content-Length']); if (!empty($messageMedia['name']) && !empty($messageMedia['ext'])) { $response->setHeader('content-disposition', "inline; filename=\"{$messageMedia['name']}{$messageMedia['ext']}\""); } diff --git a/src/MTProtoTools/ResponseInfo.php b/src/MTProtoTools/ResponseInfo.php index 39abfd437..0916a9ea1 100644 --- a/src/MTProtoTools/ResponseInfo.php +++ b/src/MTProtoTools/ResponseInfo.php @@ -20,7 +20,7 @@ declare(strict_types=1); namespace danog\MadelineProto\MTProtoTools; -use Amp\Http\Status; +use Amp\Http\HttpStatus; /** * Obtain response information for file to server. @@ -46,7 +46,7 @@ final class ResponseInfo /** * HTTP response code. */ - private int $code = Status::OK; + private int $code = HttpStatus::OK; /** * Header array. */ @@ -76,7 +76,7 @@ final class ResponseInfo [$range, $extra_ranges] = $list; } else { $this->serve = false; - $this->code = Status::RANGE_NOT_SATISFIABLE; + $this->code = HttpStatus::RANGE_NOT_SATISFIABLE; $this->headers = self::NO_CACHE; return; } @@ -94,7 +94,7 @@ final class ResponseInfo if (!empty($seek_start) && $seek_end < \abs(\intval($seek_start))) { $this->serve = false; - $this->code = Status::RANGE_NOT_SATISFIABLE; + $this->code = HttpStatus::RANGE_NOT_SATISFIABLE; $this->headers = self::NO_CACHE; return; } @@ -102,7 +102,7 @@ final class ResponseInfo $this->serve = $method !== 'HEAD'; if ($seek_start > 0 || $seek_end < $size - 1) { - $this->code = Status::PARTIAL_CONTENT; + $this->code = HttpStatus::PARTIAL_CONTENT; $this->headers['Content-Range'] = "bytes $seek_start-$seek_end/$size"; $this->headers['Content-Length'] = $seek_end - $seek_start + 1; } elseif ($size > 0) { @@ -137,9 +137,9 @@ final class ResponseInfo */ public function getCodeExplanation(): string { - $reason = Status::getReason($this->code); - $body = "
Could not use selected range.
'; } $body .= self::POWERED_BY;