cheatcodes/guzzle-hsts

v0.1.0 2016-10-25 16:57 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:53:07 UTC


README

Build Status Coverage Status Quality Score Software License Packagist Version

这是一个Guzzle中间件,用于处理HTTP Strict Transport Security

安装

确保您已安装Composer,并将guzzle-hsts添加为依赖项。

$ composer require cheatcodes/guzzle-hsts

用法

确保Guzzle使用CheatCodes\GuzzleHsts\HstsMiddleware::handler()作为中间件,将其推入处理程序堆栈。之后,所有对已知HSTS主机的http请求将自动重写为https。

示例

use CheatCodes\GuzzleHsts\HstsMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

$stack = HandlerStack::create();

// Add HSTS middleware to the handler
$stack->push(HstsMiddleware::handler());

// Initialize the Guzzle client with the handler
$client = new Client(['handler' => $stack]);

// Make a request to a https host with HSTS enabled
$client->request('GET', 'https://hsts.badssl.com/');

// Later requests to the same hosts will automatically be rewritten to https
$client->request('GET', 'http://hsts.badssl.com/');

许可证

MIT