You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-18Lines changed: 33 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,25 +104,40 @@ for more details.
104
104
### Request
105
105
106
106
A HTTP request will be sent by a client to the [Server](#server).
107
-
The `Server` will receive this request on the `data` event and
108
-
is responsible to create a request object from this data.
109
-
This object will be passed to the callback function.
110
-
111
-
The request is an instance of [PSR-7 RequestInterface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#32-psrhttpmessagerequestinterface).
112
-
113
-
As defined in PSR-7, the `getBody()` method returns a stream instance
114
-
which implements the [PSR-7 StreamInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagestreaminterface).
115
-
Note that the incoming request will be processed once the request headers have
116
-
been received, which implies that the (potentially much larger) request body
117
-
may still be outstanding (in a streaming state).
107
+
The `Server` will receive this request and
108
+
is responsible for creating a request object from this data.
109
+
The request will be processed once the request headers have
110
+
been received, irrespective of the (potentially much larger) request body (see also below).
$response->write("The method of the request is: " . $request->getMethod());
119
+
$response->end("The requested path is: " . $request->getUri()->getPath());
120
+
});
121
+
```
122
+
123
+
For more details about the request object, check out the [PSR-7 RequestInterface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#32-psrhttpmessagerequestinterface) documentation.
124
+
125
+
If you want to access the request body you can use `getBody()`.
126
+
This method returns an instance that implements both the [PSR-7 StreamInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagestreaminterface)
127
+
and the [ReactPHP ReadableStreamInterface](https://github.com/reactphp/stream#readablestreaminterface).
128
+
Because of the `ReactPHP ReadableStreamInterface` implemantation
129
+
you have opportunities like receiving large amount of data without
130
+
the need to buffer, deny the request if the body is too big or
131
+
start processing parts of the body without waiting for
132
+
the complete body data.
133
+
Use this to receive the full potential out of such scenarios and
134
+
create a fast application.
118
135
However, most of the `PSR-7 StreamInterface` methods have been
119
136
designed under the assumption of being in control of the request body.
120
-
Given that this does not apply to this server, the following
137
+
This does not apply to this server, the following
121
138
`PSR-7 StreamInterface` methods are not used and SHOULD NOT be called:
122
139
`tell()`, `eof()`, `seek()`, `rewind()`, `write()` and `read()`.
123
-
Instead, the returned stream instance *also* implements the
0 commit comments