Skip to content

[HttpClient] fix documentation of Cookies #19947

Closed
@infinitum11

Description

@infinitum11

HttpClient is used for sending HTTP requests, but not for responding to HTTP requests, so the following lines are invalid.

'headers' => [
    'Cookie' => new Cookie('flavor', 'chocolate', strtotime('+1 day')),
    // you can also pass the cookie contents as a string
    'Cookie' => 'flavor=chocolate; expires=Sat, 11 Feb 2023 12:18:13 GMT; Max-Age=86400; path=/'
],

PHP parses and populates the $_COOKIE array as follows which is wrong:

$_COOKIE = [
    "flavor" => "chocolate",
    "expires" => "Sat, 08 Jun 2024 08:34:15 GMT",
    "Max-Age" => "86400",
    "path" => "/",
    "httponly" => "",
    "samesite" => "lax",
];

So, one of the variances is to use the following syntax:

'headers' => [
    'Cookie' => 'foo=bar;baz=zap', 
    // Or an encoded format
    'Cookie' => sprintf("%s=%s", 'foo', rawurlencode('bar'))
],

See:

Metadata

Metadata

Assignees

No one assigned

    Labels

    HttpClientbughasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions