Skip to content

Commit 0402ace

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: Update serializer.rst [HttpClient] Fix how cookies are defined and sent
2 parents c2486e8 + 6edffcb commit 0402ace

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

components/serializer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ When serializing, you can set a callback to format a specific object property::
752752

753753
// all callback parameters are optional (you can omit the ones you don't use)
754754
$dateCallback = function (object $innerObject, object $outerObject, string $attributeName, ?string $format = null, array $context = []): string {
755-
return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
755+
return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ATOM) : '';
756756
};
757757

758758
$defaultContext = [

http_client.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,17 +686,21 @@ cookies automatically.
686686

687687
You can either :ref:`send cookies with the BrowserKit component <component-browserkit-sending-cookies>`,
688688
which integrates seamlessly with the HttpClient component, or manually setting
689-
the ``Cookie`` HTTP header as follows::
689+
`the Cookie HTTP request header`_ as follows::
690690

691691
use Symfony\Component\HttpClient\HttpClient;
692692
use Symfony\Component\HttpFoundation\Cookie;
693693

694694
$client = HttpClient::create([
695695
'headers' => [
696-
'Cookie' => new Cookie('flavor', 'chocolate', strtotime('+1 day')),
696+
// set one cookie as a name=value pair
697+
'Cookie' => 'flavor=chocolate',
697698

698-
// you can also pass the cookie contents as a string
699-
'Cookie' => 'flavor=chocolate; expires=Sat, 11 Feb 2023 12:18:13 GMT; Max-Age=86400; path=/'
699+
// you can set multiple cookies at once separating them with a ;
700+
'Cookie' => 'flavor=chocolate; size=medium',
701+
702+
// if needed, encode the cookie value to ensure that it contains valid characters
703+
'Cookie' => sprintf("%s=%s", 'foo', rawurlencode('...')),
700704
],
701705
]);
702706

@@ -2337,3 +2341,4 @@ you to do so, by yielding the exception from its body::
23372341
.. _`SSRF`: https://portswigger.net/web-security/ssrf
23382342
.. _`RFC 6570`: https://www.rfc-editor.org/rfc/rfc6570
23392343
.. _`HAR`: https://w3c.github.io/web-performance/specs/HAR/Overview.html
2344+
.. _`the Cookie HTTP request header`: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie

0 commit comments

Comments
 (0)