@@ -195,7 +195,7 @@ For more details about the request object, check out the documentation of
195
195
and
196
196
[ PSR-7 RequestInterface] ( https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#32-psrhttpmessagerequestinterface ) .
197
197
198
- > Currently the cookies and uploaded files are not added by the
198
+ > Currently the uploaded files are not added by the
199
199
` Server ` , but you can add these parameters by yourself using the given methods.
200
200
The next versions of this project will cover these features.
201
201
@@ -348,6 +348,43 @@ Allowed).
348
348
can in fact use a streaming response body for the tunneled application data.
349
349
See also [ example #21 ] ( examples ) for more details.
350
350
351
+ The ` getCookieParams(): string[] ` method can be used to
352
+ get all cookies sent with the current request.
353
+
354
+ ``` php
355
+ $http = new Server($socket, function (ServerRequestInterface $request) {
356
+ $key = 'react\php';
357
+
358
+ if (isset($request->getCookieParams()[$key])) {
359
+ $body = "Your cookie value is: " . $request->getCookieParams()[$key];
360
+
361
+ return new Response(
362
+ 200,
363
+ array('Content-Type' => 'text/plain'),
364
+ $body
365
+ );
366
+ }
367
+
368
+ return new Response(
369
+ 200,
370
+ array(
371
+ 'Content-Type' => 'text/plain',
372
+ 'Set-Cookie' => urlencode($key) . '=' . urlencode('test;more')
373
+ ),
374
+ "Your cookie has been set."
375
+ );
376
+ });
377
+ ```
378
+
379
+ The above example will try to set a cookie on first access and
380
+ will try to print the cookie value on all subsequent tries.
381
+ Note how the example uses the ` urlencode() ` function to encode
382
+ non-alphanumeric characters.
383
+ This encoding is also used internally when decoding the name and value of cookies
384
+ (which is in line with other implementations, such as PHP's cookie functions).
385
+
386
+ See also [ example #6 ] ( examples ) for more details.
387
+
351
388
### Response
352
389
353
390
The callback function passed to the constructor of the [ Server] ( #server )
0 commit comments