Utilities for working with PSR-7 Http Message objects.
- psr/http-message: ^1.0
- php: >=7.3
Install the latest version with:
composer require 'corpus/http-message-utils'Utility to map a Uri or ServerRequestInterface's Uri to the external scheme detected from a proxy such as an AWS load balancer.
$serverRequest = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
$serverRequest = (new \Corpus\HttpMessageUtils\ProxyAwareSchemer)->withUriWithDetectedScheme($serverRequest);<?php
namespace Corpus\HttpMessageUtils;
class ProxyAwareSchemer {
public const HTTPS_EXPECTED_SERVER_VALUES = ['HTTP_X_FORWARDED_PROTOCOL' => 'https', 'HTTP_X_FORWARDED_PROTO' => 'https', 'HTTP_X_FORWARDED_SSL' => 'on', 'HTTP_FRONT_END_HTTPS' => 'on', 'HTTP_X_URL_SCHEME' => 'https', 'HTTPS' => 'on'];
}function __construct([ ?array $proxyServerValues = null [, ?array $server = null]])- array | null
$proxyServerValues- Map of $_SERVER keys to their expected https-positive value. Defaults to self::HTTPS_EXPECTED_SERVER_VALUES - array | null
$server- Server array to inspect. Defaults to $_SERVER.
function withUriWithDetectedScheme(\Psr\Http\Message\ServerRequestInterface $serverRequest) : \Psr\Http\Message\ServerRequestInterfaceGiven a \Psr\Http\Message\ServerRequestInterface returns a new instance of ServerRequestInterface with a new Uri
having the scheme adjusted to match the detected external scheme as defined by the proxies headers.
function withDetectedScheme(\Psr\Http\Message\UriInterface $uri) : \Psr\Http\Message\UriInterfaceGiven a \Psr\Http\Message\UriInterface returns a new instance of UriInterface having the scheme adjusted to match
the detected external scheme as defined by the proxies headers.
Utility to actualize a PSR7 ResponseInterface
Sends headers and body.
$response = new \GuzzleHttp\Psr7\Response();
(new \Corpus\HttpMessageUtils\ResponseSender)->send($response);Inspired by http-interop/response-sender
MIT License Copyright (c) 2017 Woody Gilk
function __construct([ bool $fullHttpStmtHeader = false [, bool $rewindBody = true]])ResponseSender constructor.
- bool
$fullHttpStmtHeader- Setting totrueenables full HTTP statement construction which allows non-standard reason phrases and potentially mismatched protocol versions. Use with care. - bool
$rewindBody- Setting tofalseallows you to disable rewinding the body of the response before transmission.
function send(\Psr\Http\Message\ResponseInterface $response) : voidTrigger the transmission of the given \Psr\Http\Message\ResponseInterface