On this page
Requests_Cookie_Jar::before_request( string $url, array $headers, array $data, string $type, array $options )
Add Cookie header to a request if we have any
Description
As per RFC 6265, cookies are separated by ‘; ‘
Parameters
$urlstring Required$headersarray Required$dataarray Required$typestring Required$optionsarray Required
Source
File: wp-includes/Requests/Cookie/Jar.php. View all references
public function before_request($url, &$headers, &$data, &$type, &$options) {
if (!$url instanceof Requests_IRI) {
$url = new Requests_IRI($url);
}
if (!empty($this->cookies)) {
$cookies = array();
foreach ($this->cookies as $key => $cookie) {
$cookie = $this->normalize_cookie($cookie, $key);
// Skip expired cookies
if ($cookie->is_expired()) {
continue;
}
if ($cookie->domain_matches($url->host)) {
$cookies[] = $cookie->format_for_header();
}
}
$headers['Cookie'] = implode('; ', $cookies);
}
}
Related
Uses
| Uses | Description |
|---|---|
| Requests_IRI::__construct() wp-includes/Requests/IRI.php | Create a new IRI object, from a specified string |
| Requests_Cookie_Jar::normalize_cookie() wp-includes/Requests/Cookie/Jar.php | Normalise cookie data into a Requests_Cookie |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/requests_cookie_jar/before_request