kudashevs/laravel-last-modified 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kudashevs/laravel-last-modified

最新稳定版本:v1.4.0

Composer 安装命令:

composer require kudashevs/laravel-last-modified

包简介

A Laravel middleware that handles the If-Modified-Since request and Last-Modified response headers.

README 文档

README

Latest Version on Packagist Run Tests License MIT

This Laravel package contains a handler for the If-Modified-Since request and Last-Modified response headers.

Installation

You can install the package via composer:

composer require kudashevs/laravel-last-modified

Then, register the middleware in the app/Http/Kernel.php:

protected $middleware = [
    'web' => [
        ...
        \Kudashevs\LaravelLastModified\Middleware\LastModified::class,
    ],
];

You may also want to publish the configuration file (optional).

php artisan vendor:publish --provider="Kudashevs\LaravelLastModified\Providers\LastModifiedServiceProvider"

After deploying your application, check whether the headers are handled correctly.

How it works

First, the middleware identifies the last modification time of a given url by parsing the request. It tries to retrieve this information from possible origins in the following order (if it cannot retrieve the information, it moves forward):

  • a first model in the view data,
  • a first collection in the view data,
  • a first paginator in the view data,
  • a compiled view file,
  • a view file,
  • as a last resort, a fallback.

After the last modification time has been retrieved, the middleware sets the Last-Modified response header. Then, it handles the If-Modified-Since request header using the last modification time from the previous step.

Configuration

After publishing, the configuration settings are located in the config/last-modified.php file.

There configuration options are currently supported:

'enable'               # A boolean defines whether the middleware is enabled (default `true`).
'aggressive'           # A boolean defines whether the middleware returns a response immediately (default is `false`).
'fallback'             # An integer the fallback timestamp for the Last-Modifier header.
'origins'              # An array with a list of origins of the last modification time.
'exclude'              # An array with a list of paths to be excluded from processing.

, for more information please see the configuration file.

Testing

composer test

References

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Note: Please make sure to update tests as appropriate.

License

The MIT License (MIT). Please see the License file for more information.

统计信息

  • 总下载量: 98
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-11