dragon-code / laravel-http-user-agent
在所有 Http 请求中传递自己的 User Agent
1.1.0
2024-06-03 12:32 UTC
Requires
- php: ^8.2
- illuminate/config: ^10.0 || ^11.0
- illuminate/http: ^10.0 || ^11.0
- illuminate/support: ^10.0 || ^11.0
- symfony/polyfill-php83: ^1.29
Requires (Dev)
- guzzlehttp/guzzle: ^7.8
- orchestra/testbench: ^8.0 || ^9.0
- pestphp/pest: ^2.34
README
常见问题解答
- 问题:此包解决了什么问题?
- 答案:在需要显式指定发出的请求中的
User-Agent
值的情况下。在其他情况下则不需要。
安装
composer require dragon-code/laravel-http-user-agent
基本用法
就这么简单。真的 😎
安装包后,它将自动指定以下格式的 User-Agent
头部值(默认)
%s / %s - %s | %s
例如
Site Name / 1.0 - https://example.com - john.doe@example.com
其中
站点名称
-APP_NAME
环境参数的值1.0
- 应用的特定版本。如果composer.json
文件中指定了version
参数,则取其值,否则默认使用1.0
。https://example.com
-APP_URL
环境参数的值john.doe@example.com
-MAIL_FROM_ADDRESS
环境参数的值
如果您想更改此值,请在 .env
文件中添加一个新的参数 APP_USER_AGENT
。
例如
APP_USER_AGENT = "Cool Site - https://the-best.example.com"
现在,所有外部 Http 请求中的 User-Agent
头部值将指定为 Cool Site - https://the-best.example.com
。
配置
如果您需要直接访问配置文件,可以通过调用以下控制台命令将其发布到您的应用
php artisan vendor:publish --provider="DragonCode\LaravelHttpUserAgent\ServiceProvider"
执行结果将在您的应用中创建 config/http.php
文件。
您也可以通过环境设置禁用值分配
APP_USER_AGENT_ENABLED = false
许可证
此包根据 MIT 许可证 许可。