Requests_Cookie_Jar::before_request() WordPress Method

The Requests_Cookie_Jar::before_request() method is used to add cookies to a request before it is sent. This is useful for adding cookies to a request that will be sent to a different domain than the one the request is being made from.

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 ‘; ‘


Top ↑

Parameters

$url

(string)(Required)

$headers

(array)(Required)

$data

(array)(Required)

$type

(string)(Required)

$options

(array)(Required)


Top ↑

Source

File: wp-includes/Requests/Cookie/Jar.php

	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);
		}
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.