dragon-code/laravel-http-user-agent

在所有 Http 请求中传递自己的 User Agent

1.1.0 2024-06-03 12:32 UTC

This package is auto-updated.

Last update: 2024-09-03 13:01:15 UTC


README

the dragon code laravel http user agent

Stable Version Total Downloads Github Workflow Status License

常见问题解答

  • 问题:此包解决了什么问题?
  • 答案:在需要显式指定发出的请求中的 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 许可证 许可。