diff --git a/docs/PSR7-Usage.md b/docs/PSR7-Usage.md index b6d048a..34bd612 100644 --- a/docs/PSR7-Usage.md +++ b/docs/PSR7-Usage.md @@ -23,6 +23,21 @@ The following will be assumed: ### Working with HTTP Headers +#### Getting all headers + +```php +// Represent the headers as a string +foreach ($message->getHeaders() as $name => $values) { + echo sprintf('%s: %s', $name, implode(',', $values)); +} +// Emit headers iteratively +foreach ($message->getHeaders() as $name => $values) { + foreach ($values as $value) { + header(sprintf('%s: %s', $name, $value), false); + } +} +``` + #### Adding headers to response: ```php @@ -47,10 +62,15 @@ $response->hasHeader('My-Custom-Header'); // will return true #### Getting comma-separated values from a header (also applies to request) ```php +// getting value from response headers +$response->getHeaderLine('My-Custom-Header'); // will return: "My Custom Message,The second message" + +$request->withHeader('Content-Type', ['text/html', 'charset=UTF-8']); // getting value from request headers +$request->getHeaderLine('Content-Type'); // will return: "text/html,charset=UTF-8" +// sets special headers as string +$request->withHeader('Content-Type', 'text/html; charset=UTF-8'); $request->getHeaderLine('Content-Type'); // will return: "text/html; charset=UTF-8" -// getting value from response headers -$response->getHeaderLine('My-Custom-Header'); // will return: "My Custom Message; The second message" ``` #### Getting array of value from a header (also applies to request)