@@ -195,7 +195,7 @@ For more details about the request object, check out the documentation of
195195and
196196[ PSR-7 RequestInterface] ( https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#32-psrhttpmessagerequestinterface ) .
197197
198- > Currently the cookies and uploaded files are not added by the
198+ > Currently the uploaded files are not added by the
199199 ` Server ` , but you can add these parameters by yourself using the given methods.
200200 The next versions of this project will cover these features.
201201
@@ -348,6 +348,43 @@ Allowed).
348348 can in fact use a streaming response body for the tunneled application data.
349349 See also [ example #21 ] ( examples ) for more details.
350350
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+
351388### Response
352389
353390The callback function passed to the constructor of the [ Server] ( #server )
0 commit comments