@@ -76,8 +76,6 @@ multiple concurrent HTTP requests without blocking.
7676 * [ LimitConcurrentRequestsMiddleware] ( #limitconcurrentrequestsmiddleware )
7777 * [ RequestBodyBufferMiddleware] ( #requestbodybuffermiddleware )
7878 * [ RequestBodyParserMiddleware] ( #requestbodyparsermiddleware )
79- * [ ResponseInterface] ( #responseinterface )
80- * [ RequestInterface] ( #requestinterface )
8179 * [ ResponseException] ( #responseexception )
8280* [ Install] ( #install )
8381* [ Tests] ( #tests )
@@ -160,14 +158,16 @@ method. If you want to use any other or even custom HTTP request method, you can
160158use the [ ` request() ` ] ( #request ) method.
161159
162160Each of the above methods supports async operation and either * fulfills* with a
163- [ ` ResponseInterface ` ] ( #responseinterface ) or * rejects* with an ` Exception ` .
161+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface )
162+ or * rejects* with an ` Exception ` .
164163Please see the following chapter about [ promises] ( #promises ) for more details.
165164
166165### Promises
167166
168167Sending requests is async (non-blocking), so you can actually send multiple
169168requests in parallel.
170- The ` Browser ` will respond to each request with a [ ` ResponseInterface ` ] ( #responseinterface )
169+ The ` Browser ` will respond to each request with a
170+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface )
171171message, the order is not guaranteed.
172172Sending requests uses a [ Promise] ( https://github.com/reactphp/promise ) -based
173173interface that makes it easy to react to when an HTTP request is completed
@@ -474,11 +474,12 @@ the response body in small chunks as data is received and forwards this data
474474through [ ReactPHP's Stream API] ( https://github.com/reactphp/stream ) . This works
475475for (any number of) responses of arbitrary sizes.
476476
477- This means it resolves with a normal [ ` ResponseInterface ` ] ( #responseinterface ) ,
477+ This means it resolves with a normal
478+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface ) ,
478479which can be used to access the response message parameters as usual.
479480You can access the message body as usual, however it now also
480- implements ReactPHP's [ ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
481- as well as parts of the PSR-7's [ ` StreamInterface ` ] ( https://www.php-fig.org/psr/psr-7/#3-4-psr-http-message-streaminterface ) .
481+ implements [ ReactPHP's ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
482+ as well as parts of the [ PSR-7 ` StreamInterface ` ] ( https://www.php-fig.org/psr/psr-7/#34-psrhttpmessagestreaminterface ) .
482483
483484``` php
484485$browser->requestStreaming('GET', $url)->then(function (Psr\Http\Message\ResponseInterface $response) {
@@ -568,7 +569,7 @@ Besides streaming the response body, you can also stream the request body.
568569This can be useful if you want to send big POST requests (uploading files etc.)
569570or process many outgoing streams at once.
570571Instead of passing the body as a string, you can simply pass an instance
571- implementing ReactPHP's [ ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
572+ implementing [ ReactPHP's ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
572573to the [ request methods] ( #request-methods ) like this:
573574
574575``` php
@@ -620,7 +621,7 @@ $connector = new React\Socket\Connector($loop, array(
620621$browser = new React\Http\Browser($loop, $connector);
621622```
622623
623- See also the [ HTTP CONNECT proxy example] ( examples/11-http-connect-proxy.php ) .
624+ See also the [ HTTP CONNECT proxy example] ( examples/11-client- http-connect-proxy.php ) .
624625
625626### SOCKS proxy
626627
@@ -647,7 +648,7 @@ $connector = new React\Socket\Connector($loop, array(
647648$browser = new React\Http\Browser($loop, $connector);
648649```
649650
650- See also the [ SOCKS proxy example] ( examples/12-socks-proxy.php ) .
651+ See also the [ SOCKS proxy example] ( examples/12-client- socks-proxy.php ) .
651652
652653### SSH proxy
653654
@@ -676,7 +677,7 @@ $connector = new React\Socket\Connector($loop, array(
676677$browser = new React\Http\Browser($loop, $connector);
677678```
678679
679- See also the [ SSH proxy example] ( examples/13-ssh-proxy.php ) .
680+ See also the [ SSH proxy example] ( examples/13-client- ssh-proxy.php ) .
680681
681682### Unix domain sockets
682683
@@ -701,7 +702,7 @@ $client->get('http://localhost/info')->then(function (Psr\Http\Message\ResponseI
701702});
702703```
703704
704- See also the [ Unix Domain Sockets (UDS) example] ( examples/14-unix-domain-sockets.php ) .
705+ See also the [ Unix Domain Sockets (UDS) example] ( examples/14-client- unix-domain-sockets.php ) .
705706
706707
707708## Server Usage
@@ -916,9 +917,9 @@ incoming connections and then processing each incoming HTTP request.
916917The request object will be processed once the request has
917918been received by the client.
918919This request object implements the
919- [ PSR-7 ServerRequestInterface] ( https://github.com/ php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md #321-psrhttpmessageserverrequestinterface )
920+ [ PSR-7 ` ServerRequestInterface ` ] ( https://www. php-fig.org/psr/psr-7/ #321-psrhttpmessageserverrequestinterface )
920921which in turn extends the
921- [ PSR-7 RequestInterface] ( https://github.com/ php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md #32-psrhttpmessagerequestinterface )
922+ [ PSR-7 ` RequestInterface ` ] ( https://www. php-fig.org/psr/psr-7/ #32-psrhttpmessagerequestinterface )
922923and will be passed to the callback function like this.
923924
924925 ``` php
@@ -937,9 +938,9 @@ $server = new Server($loop, function (ServerRequestInterface $request) {
937938```
938939
939940For more details about the request object, also check out the documentation of
940- [ PSR-7 ServerRequestInterface] ( https://github.com/ php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md #321-psrhttpmessageserverrequestinterface )
941+ [ PSR-7 ` ServerRequestInterface ` ] ( https://www. php-fig.org/psr/psr-7/ #321-psrhttpmessageserverrequestinterface )
941942and
942- [ PSR-7 RequestInterface] ( https://github.com/ php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md #32-psrhttpmessagerequestinterface ) .
943+ [ PSR-7 ` RequestInterface ` ] ( https://www. php-fig.org/psr/psr-7/ #32-psrhttpmessagerequestinterface ) .
943944
944945#### Request parameters
945946
@@ -1149,16 +1150,19 @@ access the request body stream.
11491150In the streaming mode, this method returns a stream instance that implements both the
11501151[ PSR-7 ` StreamInterface ` ] ( https://www.php-fig.org/psr/psr-7/#34-psrhttpmessagestreaminterface )
11511152and the [ ReactPHP ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface ) .
1152- However, most of the PSR-7 ` StreamInterface ` methods have been
1153- designed under the assumption of being in control of a synchronous request body.
1153+ However, most of the
1154+ [ PSR-7 ` StreamInterface ` ] ( https://www.php-fig.org/psr/psr-7/#34-psrhttpmessagestreaminterface )
1155+ methods have been designed under the assumption of being in control of a
1156+ synchronous request body.
11541157Given that this does not apply to this server, the following
1155- PSR-7 ` StreamInterface ` methods are not used and SHOULD NOT be called:
1158+ [ PSR-7 ` StreamInterface ` ] ( https://www.php-fig.org/psr/psr-7/#34-psrhttpmessagestreaminterface )
1159+ methods are not used and SHOULD NOT be called:
11561160` tell() ` , ` eof() ` , ` seek() ` , ` rewind() ` , ` write() ` and ` read() ` .
11571161If this is an issue for your use case and/or you want to access uploaded files,
11581162it's highly recommended to use a buffered [ request body] ( #request-body ) or use the
11591163[ ` RequestBodyBufferMiddleware ` ] ( #requestbodybuffermiddleware ) instead.
1160- The ReactPHP ` ReadableStreamInterface ` gives you access to the incoming
1161- request body as the individual chunks arrive:
1164+ The [ ReactPHP ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
1165+ gives you access to the incoming request body as the individual chunks arrive:
11621166
11631167``` php
11641168$server = new React\Http\Server(
@@ -1223,7 +1227,7 @@ A response message can still be sent (unless the connection is already closed).
12231227A ` close ` event will be emitted after an ` error ` or ` end ` event.
12241228
12251229For more details about the request body stream, check out the documentation of
1226- [ ReactPHP ReadableStreamInterface] ( https://github.com/reactphp/stream#readablestreaminterface ) .
1230+ [ ReactPHP ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface ) .
12271231
12281232The ` getSize(): ?int ` method can be used to
12291233get the size of the request body, similar to PHP's ` $_SERVER['CONTENT_LENGTH'] ` variable.
@@ -1371,13 +1375,14 @@ responsible for processing the request and returning a response, which will be
13711375delivered to the client.
13721376
13731377This function MUST return an instance implementing
1374- [ PSR-7 ` ResponseInterface ` ] ( https://github.com/ php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md #33-psrhttpmessageresponseinterface )
1378+ [ PSR-7 ` ResponseInterface ` ] ( https://www. php-fig.org/psr/psr-7/ #33-psrhttpmessageresponseinterface )
13751379object or a
13761380[ ReactPHP Promise] ( https://github.com/reactphp/promise )
1377- which resolves with a PSR-7 ` ResponseInterface ` object.
1381+ which resolves with a [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface ) object.
13781382
1379- This projects ships a [ ` Response ` class] ( #response ) which implements the PSR-7
1380- ` ResponseInterface ` . In its most simple form, you can use it like this:
1383+ This projects ships a [ ` Response ` class] ( #response ) which implements the
1384+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface ) .
1385+ In its most simple form, you can use it like this:
13811386
13821387``` php
13831388$server = new React\Http\Server($loop, function (ServerRequestInterface $request) {
@@ -1392,7 +1397,8 @@ $server = new React\Http\Server($loop, function (ServerRequestInterface $request
13921397```
13931398
13941399We use this [ ` Response ` class] ( #response ) throughout our project examples, but
1395- feel free to use any other implementation of the PSR-7 ` ResponseInterface ` .
1400+ feel free to use any other implementation of the
1401+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface ) .
13961402See also the [ ` Response ` class] ( #response ) for more details.
13971403
13981404#### Deferred response
@@ -1437,11 +1443,12 @@ If a promise is resolved after the client closes, it will simply be ignored.
14371443#### Streaming outgoing response
14381444
14391445The ` Response ` class in this project supports to add an instance which implements the
1440- [ ReactPHP ReadableStreamInterface] ( https://github.com/reactphp/stream#readablestreaminterface )
1446+ [ ReactPHP ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
14411447for the response body.
14421448So you are able stream data directly into the response body.
1443- Note that other implementations of the ` PSR-7 ResponseInterface ` likely
1444- only support strings.
1449+ Note that other implementations of the
1450+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface )
1451+ may only support strings.
14451452
14461453``` php
14471454$server = new Server($loop, function (ServerRequestInterface $request) use ($loop) {
@@ -1494,8 +1501,9 @@ in this case (if applicable).
14941501 writable side of the stream.
14951502 This can be avoided by either rejecting all requests with the ` CONNECT `
14961503 method (which is what most * normal* origin HTTP servers would likely do) or
1497- or ensuring that only ever an instance of ` ReadableStreamInterface ` is
1498- used.
1504+ or ensuring that only ever an instance of
1505+ [ ReactPHP's ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
1506+ is used.
14991507>
15001508> The ` 101 ` (Switching Protocols) response code is useful for the more advanced
15011509 ` Upgrade ` requests, such as upgrading to the WebSocket protocol or
@@ -1711,13 +1719,17 @@ As such, this project supports the concept of middleware request handlers.
17111719A middleware request handler is expected to adhere the following rules:
17121720
17131721* It is a valid ` callable ` .
1714- * It accepts ` ServerRequestInterface ` as first argument and an optional
1715- ` callable ` as second argument.
1722+ * It accepts an instance implementing
1723+ [ PSR-7 ` ServerRequestInterface ` ] ( https://www.php-fig.org/psr/psr-7/#321-psrhttpmessageserverrequestinterface )
1724+ as first argument and an optional ` callable ` as second argument.
17161725* It returns either:
1717- * An instance implementing ` ResponseInterface ` for direct consumption.
1726+ * An instance implementing
1727+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface )
1728+ for direct consumption.
17181729 * Any promise which can be consumed by
17191730 [ ` Promise\resolve() ` ] ( https://reactphp.org/promise/#resolve ) resolving to a
1720- ` ResponseInterface ` for deferred consumption.
1731+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface )
1732+ for deferred consumption.
17211733 * It MAY throw an ` Exception ` (or return a rejected promise) in order to
17221734 signal an error condition and abort the chain.
17231735* It calls ` $next($request) ` to continue processing the next middleware
@@ -1772,8 +1784,8 @@ $server = new Server(
17721784Similarly, you can use the result of the ` $next ` middleware request handler
17731785function to modify the outgoing response.
17741786Note that as per the above documentation, the ` $next ` middleware request handler may return a
1775- ` ResponseInterface ` directly or one wrapped in a promise for deferred
1776- resolution.
1787+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface )
1788+ directly or one wrapped in a promise for deferred resolution.
17771789In order to simplify handling both paths, you can simply wrap this in a
17781790[ ` Promise\resolve() ` ] ( https://reactphp.org/promise/#resolve ) call like this:
17791791
@@ -1840,8 +1852,9 @@ encourages third-party middleware implementations.
18401852While we would love to support PSR-15 directly in ` react/http ` , we understand
18411853that this interface does not specifically target async APIs and as such does
18421854not take advantage of promises for [ deferred responses] ( #deferred-response ) .
1843- The gist of this is that where PSR-15 enforces a ` ResponseInterface ` return
1844- value, we also accept a ` PromiseInterface<ResponseInterface> ` .
1855+ The gist of this is that where PSR-15 enforces a
1856+ [ PSR-7 ` ResponseInterface ` ] ( https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface )
1857+ return value, we also accept a ` PromiseInterface<ResponseInterface> ` .
18451858As such, we suggest using the external
18461859[ PSR-15 middleware adapter] ( https://github.com/friends-of-reactphp/http-middleware-psr15-adapter )
18471860that uses on the fly monkey patching of these return values which makes using
@@ -2116,7 +2129,7 @@ $browser->requestStreaming('GET', $url)->then(function (Psr\Http\Message\Respons
21162129});
21172130```
21182131
2119- See also [ ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
2132+ See also [ ReactPHP's ` ReadableStreamInterface ` ] ( https://github.com/reactphp/stream#readablestreaminterface )
21202133and the [ streaming response] ( #streaming-response ) for more details,
21212134examples and possible use-cases.
21222135
@@ -2381,10 +2394,9 @@ This class implements the
23812394which in turn extends the
23822395[ PSR-7 ` MessageInterface ` ] ( https://www.php-fig.org/psr/psr-7/#31-psrhttpmessagemessageinterface ) .
23832396
2384- > Internally, this class extends the underlying ` \RingCentral\Psr7\Response `
2385- class. The only difference is that this class will accept implemenations
2386- of ReactPHPs ` ReadableStreamInterface ` for the ` $body ` argument. This base
2387- class is considered an implementation detail that may change in the future.
2397+ > Internally, this implementation builds on top of an existing incoming
2398+ response message and only adds required streaming support. This base class is
2399+ considered an implementation detail that may change in the future.
23882400
23892401#### ServerRequest
23902402
@@ -2593,7 +2605,8 @@ Instead of relying on these superglobals, you can use the
25932605` $request->getParsedBody() ` and ` $request->getUploadedFiles() ` methods
25942606as defined by PSR-7.
25952607
2596- Accordingly, each file upload will be represented as instance implementing [ ` UploadedFileInterface ` ] ( https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#36-psrhttpmessageuploadedfileinterface ) .
2608+ Accordingly, each file upload will be represented as instance implementing the
2609+ [ PSR-7 ` UploadedFileInterface ` ] ( https://www.php-fig.org/psr/psr-7/#36-psrhttpmessageuploadedfileinterface ) .
25972610Due to its blocking nature, the ` moveTo() ` method is not available and throws
25982611a ` RuntimeException ` instead.
25992612You can use ` $contents = (string)$file->getStream(); ` to access the file
@@ -2697,26 +2710,6 @@ new RequestBodyParserMiddleware(10 * 1024, 100); // 100 files with 10 KiB each
26972710 If you want to respect this setting, you have to check its value and
26982711 effectively avoid using this middleware entirely.
26992712
2700- ### ResponseInterface
2701-
2702- The ` Psr\Http\Message\ResponseInterface ` represents the incoming response received from the [ ` Browser ` ] ( #browser ) .
2703-
2704- This is a standard interface defined in
2705- [ PSR-7: HTTP message interfaces] ( https://www.php-fig.org/psr/psr-7/ ) , see its
2706- [ ` ResponseInterface ` definition] ( https://www.php-fig.org/psr/psr-7/#3-3-psr-http-message-responseinterface )
2707- which in turn extends the
2708- [ ` MessageInterface ` definition] ( https://www.php-fig.org/psr/psr-7/#3-1-psr-http-message-messageinterface ) .
2709-
2710- ### RequestInterface
2711-
2712- The ` Psr\Http\Message\RequestInterface ` represents the outgoing request to be sent via the [ ` Browser ` ] ( #browser ) .
2713-
2714- This is a standard interface defined in
2715- [ PSR-7: HTTP message interfaces] ( https://www.php-fig.org/psr/psr-7/ ) , see its
2716- [ ` RequestInterface ` definition] ( https://www.php-fig.org/psr/psr-7/#3-2-psr-http-message-requestinterface )
2717- which in turn extends the
2718- [ ` MessageInterface ` definition] ( https://www.php-fig.org/psr/psr-7/#3-1-psr-http-message-messageinterface ) .
2719-
27202713### ResponseException
27212714
27222715The ` ResponseException ` is an ` Exception ` sub-class that will be used to reject
@@ -2728,7 +2721,7 @@ The `getCode(): int` method can be used to
27282721return the HTTP response status code.
27292722
27302723The ` getResponse(): ResponseInterface ` method can be used to
2731- access its underlying [ ` ResponseInterface ` ] ( #responseinterface ) object.
2724+ access its underlying response object.
27322725
27332726## Install
27342727
0 commit comments