Skip to content

CheatCodes/guzzle-hsts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

guzzle-hsts

Build Status Coverage Status Quality Score Software License Packagist Version

This is a Guzzle middleware to handle HTTP Strict Transport Security.

Installation

Make sure you have Composer installed and add guzzle-hsts as a dependency.

$ composer require cheatcodes/guzzle-hsts

Usage

Make sure Guzzle uses the CheatCodes\GuzzleHsts\HstsMiddleware::handler() as a middleware by pushing it onto the handler stack. After that, all http requests to known HSTS hosts will be automatically rewritten to https.

An example:

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/');

License

MIT

About

Guzzle middleware to handle HSTS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages