Skip to content

Commit

Permalink
Added fig/http-message-util package
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar committed Feb 4, 2022
1 parent 78cb718 commit 6a5d552
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dragon-code/laravel-cache": "^2.10",
"dragon-code/simple-data-transfer-object": "^2.1",
"dragon-code/support": "^5.6",
"fig/http-message-util": "^1.1",
"illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0",
Expand Down
11 changes: 9 additions & 2 deletions src/Middlewares/CheckLastModified.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Closure;
use DragonCode\LastModified\Facades\Config;
use DragonCode\LastModified\Services\Checker;
use Fig\Http\Message\RequestMethodInterface;
use Fig\Http\Message\StatusCodeInterface;
use Illuminate\Http\Request;

class CheckLastModified
Expand All @@ -33,7 +35,7 @@ public function handle(Request $request, Closure $next)
$service = $this->service($request);

if ($service->isNotModified()) {
return response(null, 304);
return response(null, StatusCodeInterface::STATUS_NOT_MODIFIED);
}

return $this->setLastModified($request, $next, $service);
Expand Down Expand Up @@ -63,6 +65,11 @@ protected function disallowMethod(Request $request): bool
{
$method = $request->getRealMethod();

return ! in_array($method, ['GET', 'HEAD'], true);
return ! in_array($method, $this->requestMethods(), true);
}

protected function requestMethods(): array
{
return [RequestMethodInterface::METHOD_GET, RequestMethodInterface::METHOD_HEAD];
}
}
3 changes: 2 additions & 1 deletion tests/Concerns/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Tests\Concerns;

use Carbon\Carbon;
use Fig\Http\Message\RequestMethodInterface;
use Illuminate\Http\Request;
use Lmc\HttpConstants\Header;

Expand All @@ -44,7 +45,7 @@ protected function requestInstance(Carbon $date = null): Request
{
$server = ! empty($date) ? $this->getRequestDateHeader($date) : [];

return Request::create($this->url(), 'GET', [], [], [], $server);
return Request::create($this->url(), RequestMethodInterface::METHOD_GET, [], [], [], $server);
}

protected function getRequestDateHeader(Carbon $date): array
Expand Down

0 comments on commit 6a5d552

Please sign in to comment.