/**
* HTTP API: WP_Http_Cookie class
*
* @package WordPress
* @subpackage HTTP
* @since 4.4.0
*/
/**
* Core class used to encapsulate a single cookie object for internal use.
*
* Returned cookies are represented using this class, and when cookies are set, if they are not
* already a WP_Http_Cookie() object, then they are turned into one.
*
* @todo The WordPress convention is to use underscores instead of camelCase for function and method
* names. Need to switch to use underscores instead for the methods.
*
* @since 2.8.0
*/
#[AllowDynamicProperties]
class WP_Http_Cookie {
/**
* Cookie name.
*
* @since 2.8.0
*
* @var string
*/
public $name;
/**
* Cookie value.
*
* @since 2.8.0
*
* @var string
*/
public $value;
/**
* When the cookie expires. Unix timestamp or formatted date.
*
* @since 2.8.0
*
* @var string|int|null
*/
public $expires;
/**
* Cookie URL path.
*
* @since 2.8.0
*
* @var string
*/
public $path;
/**
* Cookie Domain.
*
* @since 2.8.0
*
* @var string
*/
public $domain;
/**
* Cookie port or comma-separated list of ports.
*
* @since 2.8.0
*
* @var int|string
*/
public $port;
/**
* host-only flag.
*
* @since 5.2.0
*
* @var bool
*/
public $host_only;
/**
* Sets up this cookie object.
*
* The parameter $data should be either an associative array containing the indices names below
* or a header string detailing it.
*
* @since 2.8.0
* @since 5.2.0 Added `host_only` to the `$data` parameter.
*
* @param string|array $data {
* Raw cookie data as header string or data array.
*
* @type string $name Cookie name.
* @type mixed $value Value. Should NOT already be urlencoded.
* @type string|int|null $expires Optional. Unix timestamp or formatted date. Default null.
* @type string $path Optional. Path. Default '/'.
* @type string $domain Optional. Domain. Default host of parsed $requested_url.
* @type int|string $port Optional. Port or comma-separated list of ports. Default null.
* @type bool $host_only Optional. host-only storage flag. Default true.
* }
* @param string $requested_url The URL which the cookie was set on, used for default $domain
* and $port values.
*/
public function __construct( $data, $requested_url = '' ) {
if ( $requested_url ) {
$parsed_url = parse_url( $requested_url );
}
if ( isset( $parsed_url['host'] ) ) {
$this->domain = $parsed_url['host'];
}
$this->path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
if ( ! str_ends_with( $this->path, '/' ) ) {
$this->path = dirname( $this->path ) . '/';
}
if ( is_string( $data ) ) {
// Assume it's a header string direct from a previous request.
$pairs = explode( ';', $data );
// Special handling for first pair; name=value. Also be careful of "=" in value.
$name = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) );
$value = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 );
$this->name = $name;
$this->value = urldecode( $value );
// Removes name=value from items.
array_shift( $pairs );
// Set everything else as a property.
foreach ( $pairs as $pair ) {
$pair = rtrim( $pair );
// Handle the cookie ending in ; which results in an empty final pair.
if ( empty( $pair ) ) {
continue;
}
list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' );
$key = strtolower( trim( $key ) );
if ( 'expires' === $key ) {
$val = strtotime( $val );
}
$this->$key = $val;
}
} else {
if ( ! isset( $data['name'] ) ) {
return;
}
// Set properties based directly on parameters.
foreach ( array( 'name', 'value', 'path', 'domain', 'port', 'host_only' ) as $field ) {
if ( isset( $data[ $field ] ) ) {
$this->$field = $data[ $field ];
}
}
if ( isset( $data['expires'] ) ) {
$this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] );
} else {
$this->expires = null;
}
}
}
/**
* Confirms that it's OK to send this cookie to the URL checked against.
*
* Decision is based on RFC 2109/2965, so look there for details on validity.
*
* @since 2.8.0
*
* @param string $url URL you intend to send this cookie to
* @return bool true if allowed, false otherwise.
*/
public function test( $url ) {
if ( is_null( $this->name ) ) {
return false;
}
// Expires - if expired then nothing else matters.
if ( isset( $this->expires ) && time() > $this->expires ) {
return false;
}
// Get details on the URL we're thinking about sending to.
$url = parse_url( $url );
$url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' === $url['scheme'] ? 443 : 80 );
$url['path'] = isset( $url['path'] ) ? $url['path'] : '/';
// Values to use for comparison against the URL.
$path = isset( $this->path ) ? $this->path : '/';
$port = isset( $this->port ) ? $this->port : null;
$domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] );
if ( false === stripos( $domain, '.' ) ) {
$domain .= '.local';
}
// Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
$domain = ( str_starts_with( $domain, '.' ) ) ? substr( $domain, 1 ) : $domain;
if ( ! str_ends_with( $url['host'], $domain ) ) {
return false;
}
// Port - supports "port-lists" in the format: "80,8000,8080".
if ( ! empty( $port ) && ! in_array( $url['port'], array_map( 'intval', explode( ',', $port ) ), true ) ) {
return false;
}
// Path - request path must start with path restriction.
if ( ! str_starts_with( $url['path'], $path ) ) {
return false;
}
return true;
}
/**
* Convert cookie name and value back to header string.
*
* @since 2.8.0
*
* @return string Header encoded cookie name and value.
*/
public function getHeaderValue() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
if ( ! isset( $this->name ) || ! isset( $this->value ) ) {
return '';
}
/**
* Filters the header-encoded cookie value.
*
* @since 3.4.0
*
* @param string $value The cookie value.
* @param string $name The cookie name.
*/
return $this->name . '=' . apply_filters( 'wp_http_cookie_value', $this->value, $this->name );
}
/**
* Retrieve cookie header for usage in the rest of the WordPress HTTP API.
*
* @since 2.8.0
*
* @return string
*/
public function getFullHeader() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
return 'Cookie: ' . $this->getHeaderValue();
}
/**
* Retrieves cookie attributes.
*
* @since 4.6.0
*
* @return array {
* List of attributes.
*
* @type string|int|null $expires When the cookie expires. Unix timestamp or formatted date.
* @type string $path Cookie URL path.
* @type string $domain Cookie domain.
* }
*/
public function get_attributes() {
return array(
'expires' => $this->expires,
'path' => $this->path,
'domain' => $this->domain,
);
}
}
� �}�v�ƖV��/[dB�IQ9�d;�r,)9>�G
E2 (��Ѭ��y����y�O�/���
7�HIIw��!��]�V�v��r��������/�8�8���E��%����Q�"�a4w�=U����v�1�G㨫��
��wl�+tؗ�Q�]E�j�C;#?��`��6ܪ�M��/��Q7R|g:��P���ȋG6
sL:P.Ci:�aU�n�2�����l?B'42�96��F}���ܖ�g�Ƅ��+��|/�$"H���mE�E�l���Bll ��C�G�w:u-cN~�pl�����������,���xQ��ۛײ=1FT5 3]�Ft ����a�Sh�AA@cy��TO�<��ier�pP��;۔�Kj����Dk���r����:�=�
��!�����=Eư:�T�o�XK�ô�d8P��Q�Ds4k��c�Fd{���w��P%}�+����'�3�O����������W�Z��3pE�+;�&��p[MQ�/du�}�[]���PԶ2����ޖ!�P8�p=�q���ۼPZD�#�Ҹ2O�|K��|::><;�D�Uvg�ky���̧��>�Qd����ɍ40Bz8RW��Y����Y�F��R��P�����QU���JK�n��"P��#x �F��6�~���{P�T��H���8X�������vMgj!�ː%02��3����f�Uե���� 9�!�%��.GQ����Z}2��&�jɮ��+# ^%��^�N�-�D���E��p��=�avi%�'�dL�nɥ3r���+Ùғa�|�i���@mU��?��%����ɻj��nd票\���c$w{���K@Y�UD
>P3*����R��>y�]Y@j����Z�q��sp�5�0�y�VG��)�nl��j`��K��eɣ��F�&-fq$����O9��砮§�le���s#�L��[�����})���B����=V�I�:�Hj!��L�?�RA�@d�o-��a\��(����m��'}���;��4x�x�95=�>Rga�w�,���d8/N�{��1L�rB28���N�$qK�����a��C�-�r3���B�W�}
�μ�D�-W�~ɨ"�P�U�}x�T1����������!xP�&����p4�>�7�'����
� �TO�sDZĽ�ʽ�fZ%�~�V�*�U��k�mǂ�u[����7�CPnɃ0����N��
�J���[dEXŗ�[�8�߰6��������6������
e�OP̩�����
�zc��%����y�@�<�~n����n��ZBq}��$%�>h�y}���B�0�{�e��$y�Kp�R?�hHr��
2iդ���?���j����f u5۩�[ɦf:��'N�Ę}
y^ي�hA�BC):����s��w�xg�E�/�-�SuK�FoAѠ��ݰy���-��� ��B/�+�L�ϼ|�^z�[��PI�r$Y�T�A�K��-6o�(�R
ʕlu���y+��?m�W�mA��� ����a������A�[��L"�V���]����5
�%����ZNt�}
�6XM]�0���\�
o�O��t�J���c�����{0�'d$w��x���[��G���k��g��%���HA3�b�����Q��EIXh�����f���#���r�V����sp3�XB8@��2�_��G�3���˕C�2F��˗�a���?;��c��pLi�Gl���M#���ݓA*�a�ᷛua�C%��OT%Ԫ�n��6�HM�e�=�)�`Es��s
#�k9�Xvwwp> ��k�+_Yqr���c١��.�H�{�l�Qr^`ѠK`���u-�c�]�-歈F'9,X.ʘ��v�D%jUm-e��"�ʆc� LV��8��F����+�R슁F.�v7��Yc�ā�_e�F0��$�"֍���Ba8d�M���1�1B���F���l0�&��Q����s���t8�R��"���Z5��MH˞������`-��٢0pg�3<1�,�s�Tm6�$�#>� KҪ�Z-I�a���洪�7��6�%����dl$f2#H+Y�H5=b��F*����20��0֖e#����Y��f�[U�k]RWjk�jr�KjJ� ���@:��� �5���T:k�: �%Ek.�1��PQP-]�Te�0��ppj�cy��zjms�A>���k��7*�`��j[F��ʾ�-9��W��C��ΙB����( V�8��*��Jcs��zW���L+ �X栱��8P����d�+�oSK��pg��f�FW� ����� hg��袌#t�s.��/�`�3��DI�5,:���QjV�z��뭊V&�3L,i�F��Ab�L4U}V^IzQ�)��W�/i�t`��V�jEW����I��$���N
zC5U&6*�*�b��L����z�RB�ڪԛ��.�e&Uȃ�XS z�]��6��B��Ӹ���yҜ�Df�,�N�lՁV+>csZEӱ�;e�g5�*��i�h��ͣ�aa�^�o'i@�ޮ��T� ���ww�aU��M����^�9" x��rj��7��wP@,��H���
�W&��8hI�4��mԚ�_7�V�4=��A��u��r�D[�]����Lz�7`t�vJ��3��k�X�MpY�;&u�!ԃ�0\O]ՙ�hz�h5Vٚ~�Ml����:Ъ�I�ס�k`K����k�L �����J y����:(���Ms�uVח�B�0!��G�aB�^�dH��4[k@� ���o`~��� zU_��Z��^��FUm��8\�]F�T����:a\��/�b\ڢ�Ipr�}4Ԃ��U��;�S�EeWR�q5Z��/.�b��H���+ `������ ywP�;Ӏ��v�5��C��7#�G#��H�(��<����d�M2JǷ��b6~ȳ ��g���e~'�Lh�4X*Dn���B,��|���9@S�-�V#�EN�bN'nX�'=��5E2j+.���2�