Skip to content

Commit 0931d80

Browse files
committed
Update docs
1 parent 6a7c380 commit 0931d80

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

README.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,80 @@ namespace Corpus\HttpMessageUtils;
4242

4343
class ProxyAwareSchemer {
4444
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'];
45+
public const PORT_EXPECTED_SERVER_KEYS = ['HTTP_X_FORWARDED_PORT'];
46+
/** Value for `default port` arguments to remove the port from the URI */
47+
public const REMOVE_PORT = -65536;
4548
}
4649
```
4750

4851
#### Method: ProxyAwareSchemer->__construct
4952

5053
```php
51-
function __construct([ ?array $proxyServerValues = null [, ?array $server = null]])
54+
function __construct([ ?array $server = null [, ?array $proxyServerHttpsKeyValues = null [, ?array $proxyServerPortKeys = null]]])
5255
```
5356

5457
##### Parameters:
5558

56-
- ***array*** | ***null*** `$proxyServerValues` - Map of $_SERVER keys to their expected https-positive value. Defaults to
57-
self::HTTPS_EXPECTED_SERVER_VALUES
5859
- ***array*** | ***null*** `$server` - Server array to inspect. Defaults to $_SERVER.
60+
- ***array*** | ***null*** `$proxyServerHttpsKeyValues` - Map of $_SERVER keys to their expected https-positive value.
61+
Defaults to ProxyAwareSchemer::HTTPS_EXPECTED_SERVER_VALUES
62+
- ***string[]*** | ***null*** `$` - Array of $_SERVER keys to check for a forwarded port value.
5963

6064
---
6165

6266
#### Method: ProxyAwareSchemer->withUriWithDetectedScheme
6367

6468
```php
65-
function withUriWithDetectedScheme(\Psr\Http\Message\ServerRequestInterface $serverRequest) : \Psr\Http\Message\ServerRequestInterface
69+
function withUriWithDetectedScheme(\Psr\Http\Message\ServerRequestInterface $serverRequest [, bool $detectPort = true [, ?int $defaultOnHttps = self::REMOVE_PORT]]) : \Psr\Http\Message\ServerRequestInterface
6670
```
6771

6872
Given a \Psr\Http\Message\ServerRequestInterface returns a new instance of ServerRequestInterface with a new Uri
6973
having the scheme adjusted to match the detected external scheme as defined by the proxies headers.
7074

75+
##### Parameters:
76+
77+
- ***bool*** `$detectPort` - Enable / Disable proxy port sniffing.
78+
- ***int*** | ***null*** `$defaultOnHttps` - Default port to use if sniffing fails but HTTPS proxy is detected.
79+
Defaults to ProxyAwareSchemer::REMOVE_PORT which removes the port information
80+
from the URI.
81+
Passing null will leave port as-is.
82+
7183
---
7284

7385
#### Method: ProxyAwareSchemer->withDetectedScheme
7486

7587
```php
76-
function withDetectedScheme(\Psr\Http\Message\UriInterface $uri) : \Psr\Http\Message\UriInterface
88+
function withDetectedScheme(\Psr\Http\Message\UriInterface $uri [, bool $detectPort = true [, ?int $defaultOnHttps = self::REMOVE_PORT]]) : \Psr\Http\Message\UriInterface
7789
```
7890

79-
Given a \Psr\Http\Message\UriInterface returns a new instance of UriInterface having the scheme adjusted to match
91+
Given a \Psr\Http\Message\UriInterface returns a instance of UriInterface having the scheme adjusted to match
8092
the detected external scheme as defined by the proxies headers.
8193

94+
##### Parameters:
95+
96+
- ***bool*** `$detectPort` - Enable / Disable proxy port sniffing.
97+
- ***int*** | ***null*** `$defaultOnHttps` - Default port to use if sniffing fails but HTTPS proxy is detected.
98+
Defaults to ProxyAwareSchemer::REMOVE_PORT which removes the port information
99+
from the URI.
100+
Passing null will leave port as-is.
101+
102+
---
103+
104+
#### Method: ProxyAwareSchemer->withDetectedPort
105+
106+
```php
107+
function withDetectedPort(\Psr\Http\Message\UriInterface $uri [, ?int $default = null]) : \Psr\Http\Message\UriInterface
108+
```
109+
110+
Given a \Psr\Http\Message\UriInterface returns a instance of UriInterface having the port adjusted to match
111+
the detected external scheme as defined by the proxies headers.
112+
113+
##### Parameters:
114+
115+
- ***int*** | ***null*** `$default` - Defines a default fallback port.
116+
Passing ProxyAwareSchemer::REMOVE_PORT will default to removing the port information.
117+
Defaults to null - null leaves port as-is.
118+
82119
### Class: \Corpus\HttpMessageUtils\ResponseSender
83120

84121
Utility to actualize a PSR7 ResponseInterface

src/ProxyAwareSchemer.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,17 @@ public function __construct(
7171
/**
7272
* Given a \Psr\Http\Message\ServerRequestInterface returns a new instance of ServerRequestInterface with a new Uri
7373
* having the scheme adjusted to match the detected external scheme as defined by the proxies headers.
74+
*
75+
* @param bool $detectPort Enable / Disable proxy port sniffing.
76+
* @param int|null $defaultOnHttps Default port to use if sniffing fails but HTTPS proxy is detected.
77+
* Defaults to ProxyAwareSchemer::REMOVE_PORT which removes the port information
78+
* from the URI.
79+
* Passing null will leave port as-is.
7480
*/
7581
public function withUriWithDetectedScheme(
76-
ServerRequestInterface $serverRequest, bool $detectPort = true, ?int $defaultOnHttps = self::REMOVE_PORT
82+
ServerRequestInterface $serverRequest,
83+
bool $detectPort = true,
84+
?int $defaultOnHttps = self::REMOVE_PORT
7785
) : ServerRequestInterface {
7886
return $serverRequest->withUri(
7987
$this->withDetectedScheme($serverRequest->getUri(), $detectPort, $defaultOnHttps)
@@ -83,6 +91,12 @@ public function withUriWithDetectedScheme(
8391
/**
8492
* Given a \Psr\Http\Message\UriInterface returns a instance of UriInterface having the scheme adjusted to match
8593
* the detected external scheme as defined by the proxies headers.
94+
*
95+
* @param bool $detectPort Enable / Disable proxy port sniffing.
96+
* @param int|null $defaultOnHttps Default port to use if sniffing fails but HTTPS proxy is detected.
97+
* Defaults to ProxyAwareSchemer::REMOVE_PORT which removes the port information
98+
* from the URI.
99+
* Passing null will leave port as-is.
86100
*/
87101
public function withDetectedScheme(
88102
UriInterface $uri,
@@ -106,7 +120,9 @@ public function withDetectedScheme(
106120
* Given a \Psr\Http\Message\UriInterface returns a instance of UriInterface having the port adjusted to match
107121
* the detected external scheme as defined by the proxies headers.
108122
*
109-
* @param int|null $default Defines a default fallback port
123+
* @param int|null $default Defines a default fallback port.
124+
* Passing ProxyAwareSchemer::REMOVE_PORT will default to removing the port information.
125+
* Defaults to null - null leaves port as-is.
110126
*/
111127
public function withDetectedPort( UriInterface $uri, ?int $default = null ) : UriInterface {
112128
foreach( $this->proxyServerPortKeys as $portKey ) {

0 commit comments

Comments
 (0)