From 7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 7 Jan 2020 13:06:14 +0100 Subject: Added wordpress --- srcs/wordpress/wp-includes/Requests/Auth.php | 33 + srcs/wordpress/wp-includes/Requests/Auth/Basic.php | 88 ++ srcs/wordpress/wp-includes/Requests/Cookie.php | 505 +++++++++ srcs/wordpress/wp-includes/Requests/Cookie/Jar.php | 175 ++++ srcs/wordpress/wp-includes/Requests/Exception.php | 62 ++ .../wp-includes/Requests/Exception/HTTP.php | 71 ++ .../wp-includes/Requests/Exception/HTTP/304.php | 27 + .../wp-includes/Requests/Exception/HTTP/305.php | 27 + .../wp-includes/Requests/Exception/HTTP/306.php | 27 + .../wp-includes/Requests/Exception/HTTP/400.php | 27 + .../wp-includes/Requests/Exception/HTTP/401.php | 27 + .../wp-includes/Requests/Exception/HTTP/402.php | 27 + .../wp-includes/Requests/Exception/HTTP/403.php | 27 + .../wp-includes/Requests/Exception/HTTP/404.php | 27 + .../wp-includes/Requests/Exception/HTTP/405.php | 27 + .../wp-includes/Requests/Exception/HTTP/406.php | 27 + .../wp-includes/Requests/Exception/HTTP/407.php | 27 + .../wp-includes/Requests/Exception/HTTP/408.php | 27 + .../wp-includes/Requests/Exception/HTTP/409.php | 27 + .../wp-includes/Requests/Exception/HTTP/410.php | 27 + .../wp-includes/Requests/Exception/HTTP/411.php | 27 + .../wp-includes/Requests/Exception/HTTP/412.php | 27 + .../wp-includes/Requests/Exception/HTTP/413.php | 27 + .../wp-includes/Requests/Exception/HTTP/414.php | 27 + .../wp-includes/Requests/Exception/HTTP/415.php | 27 + .../wp-includes/Requests/Exception/HTTP/416.php | 27 + .../wp-includes/Requests/Exception/HTTP/417.php | 27 + .../wp-includes/Requests/Exception/HTTP/418.php | 29 + .../wp-includes/Requests/Exception/HTTP/428.php | 29 + .../wp-includes/Requests/Exception/HTTP/429.php | 29 + .../wp-includes/Requests/Exception/HTTP/431.php | 29 + .../wp-includes/Requests/Exception/HTTP/500.php | 27 + .../wp-includes/Requests/Exception/HTTP/501.php | 27 + .../wp-includes/Requests/Exception/HTTP/502.php | 27 + .../wp-includes/Requests/Exception/HTTP/503.php | 27 + .../wp-includes/Requests/Exception/HTTP/504.php | 27 + .../wp-includes/Requests/Exception/HTTP/505.php | 27 + .../wp-includes/Requests/Exception/HTTP/511.php | 29 + .../Requests/Exception/HTTP/Unknown.php | 44 + .../wp-includes/Requests/Exception/Transport.php | 5 + .../Requests/Exception/Transport/cURL.php | 56 + srcs/wordpress/wp-includes/Requests/Hooker.php | 33 + srcs/wordpress/wp-includes/Requests/Hooks.php | 68 ++ .../wordpress/wp-includes/Requests/IDNAEncoder.php | 388 +++++++ srcs/wordpress/wp-includes/Requests/IPv6.php | 190 ++++ srcs/wordpress/wp-includes/Requests/IRI.php | 1084 ++++++++++++++++++++ srcs/wordpress/wp-includes/Requests/Proxy.php | 35 + srcs/wordpress/wp-includes/Requests/Proxy/HTTP.php | 151 +++ srcs/wordpress/wp-includes/Requests/Response.php | 121 +++ .../wp-includes/Requests/Response/Headers.php | 98 ++ srcs/wordpress/wp-includes/Requests/SSL.php | 152 +++ srcs/wordpress/wp-includes/Requests/Session.php | 266 +++++ srcs/wordpress/wp-includes/Requests/Transport.php | 41 + .../wp-includes/Requests/Transport/cURL.php | 542 ++++++++++ .../wp-includes/Requests/Transport/fsockopen.php | 444 ++++++++ .../Requests/Utility/CaseInsensitiveDictionary.php | 103 ++ .../Requests/Utility/FilteredIterator.php | 45 + 57 files changed, 5674 insertions(+) create mode 100644 srcs/wordpress/wp-includes/Requests/Auth.php create mode 100644 srcs/wordpress/wp-includes/Requests/Auth/Basic.php create mode 100644 srcs/wordpress/wp-includes/Requests/Cookie.php create mode 100644 srcs/wordpress/wp-includes/Requests/Cookie/Jar.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/304.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/305.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/306.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/400.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/401.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/402.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/403.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/404.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/405.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/406.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/407.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/408.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/409.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/410.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/411.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/412.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/413.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/414.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/415.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/416.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/417.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/418.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/428.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/429.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/431.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/500.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/501.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/502.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/503.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/504.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/505.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/511.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/HTTP/Unknown.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/Transport.php create mode 100644 srcs/wordpress/wp-includes/Requests/Exception/Transport/cURL.php create mode 100644 srcs/wordpress/wp-includes/Requests/Hooker.php create mode 100644 srcs/wordpress/wp-includes/Requests/Hooks.php create mode 100644 srcs/wordpress/wp-includes/Requests/IDNAEncoder.php create mode 100644 srcs/wordpress/wp-includes/Requests/IPv6.php create mode 100644 srcs/wordpress/wp-includes/Requests/IRI.php create mode 100644 srcs/wordpress/wp-includes/Requests/Proxy.php create mode 100644 srcs/wordpress/wp-includes/Requests/Proxy/HTTP.php create mode 100644 srcs/wordpress/wp-includes/Requests/Response.php create mode 100644 srcs/wordpress/wp-includes/Requests/Response/Headers.php create mode 100644 srcs/wordpress/wp-includes/Requests/SSL.php create mode 100644 srcs/wordpress/wp-includes/Requests/Session.php create mode 100644 srcs/wordpress/wp-includes/Requests/Transport.php create mode 100644 srcs/wordpress/wp-includes/Requests/Transport/cURL.php create mode 100644 srcs/wordpress/wp-includes/Requests/Transport/fsockopen.php create mode 100644 srcs/wordpress/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php create mode 100644 srcs/wordpress/wp-includes/Requests/Utility/FilteredIterator.php (limited to 'srcs/wordpress/wp-includes/Requests') diff --git a/srcs/wordpress/wp-includes/Requests/Auth.php b/srcs/wordpress/wp-includes/Requests/Auth.php new file mode 100644 index 0000000..bca4109 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Auth.php @@ -0,0 +1,33 @@ +user, $this->pass) = $args; + } + } + + /** + * Register the necessary callbacks + * + * @see curl_before_send + * @see fsockopen_header + * @param Requests_Hooks $hooks Hook system + */ + public function register(Requests_Hooks &$hooks) { + $hooks->register('curl.before_send', array(&$this, 'curl_before_send')); + $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header')); + } + + /** + * Set cURL parameters before the data is sent + * + * @param resource $handle cURL resource + */ + public function curl_before_send(&$handle) { + curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString()); + } + + /** + * Add extra headers to the request before sending + * + * @param string $out HTTP header string + */ + public function fsockopen_header(&$out) { + $out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString())); + } + + /** + * Get the authentication string (user:pass) + * + * @return string + */ + public function getAuthString() { + return $this->user . ':' . $this->pass; + } +} \ No newline at end of file diff --git a/srcs/wordpress/wp-includes/Requests/Cookie.php b/srcs/wordpress/wp-includes/Requests/Cookie.php new file mode 100644 index 0000000..6fccec6 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Cookie.php @@ -0,0 +1,505 @@ +name = $name; + $this->value = $value; + $this->attributes = $attributes; + $default_flags = array( + 'creation' => time(), + 'last-access' => time(), + 'persistent' => false, + 'host-only' => true, + ); + $this->flags = array_merge($default_flags, $flags); + + $this->reference_time = time(); + if ($reference_time !== null) { + $this->reference_time = $reference_time; + } + + $this->normalize(); + } + + /** + * Check if a cookie is expired. + * + * Checks the age against $this->reference_time to determine if the cookie + * is expired. + * + * @return boolean True if expired, false if time is valid. + */ + public function is_expired() { + // RFC6265, s. 4.1.2.2: + // If a cookie has both the Max-Age and the Expires attribute, the Max- + // Age attribute has precedence and controls the expiration date of the + // cookie. + if (isset($this->attributes['max-age'])) { + $max_age = $this->attributes['max-age']; + return $max_age < $this->reference_time; + } + + if (isset($this->attributes['expires'])) { + $expires = $this->attributes['expires']; + return $expires < $this->reference_time; + } + + return false; + } + + /** + * Check if a cookie is valid for a given URI + * + * @param Requests_IRI $uri URI to check + * @return boolean Whether the cookie is valid for the given URI + */ + public function uri_matches(Requests_IRI $uri) { + if (!$this->domain_matches($uri->host)) { + return false; + } + + if (!$this->path_matches($uri->path)) { + return false; + } + + return empty($this->attributes['secure']) || $uri->scheme === 'https'; + } + + /** + * Check if a cookie is valid for a given domain + * + * @param string $string Domain to check + * @return boolean Whether the cookie is valid for the given domain + */ + public function domain_matches($string) { + if (!isset($this->attributes['domain'])) { + // Cookies created manually; cookies created by Requests will set + // the domain to the requested domain + return true; + } + + $domain_string = $this->attributes['domain']; + if ($domain_string === $string) { + // The domain string and the string are identical. + return true; + } + + // If the cookie is marked as host-only and we don't have an exact + // match, reject the cookie + if ($this->flags['host-only'] === true) { + return false; + } + + if (strlen($string) <= strlen($domain_string)) { + // For obvious reasons, the string cannot be a suffix if the domain + // is shorter than the domain string + return false; + } + + if (substr($string, -1 * strlen($domain_string)) !== $domain_string) { + // The domain string should be a suffix of the string. + return false; + } + + $prefix = substr($string, 0, strlen($string) - strlen($domain_string)); + if (substr($prefix, -1) !== '.') { + // The last character of the string that is not included in the + // domain string should be a %x2E (".") character. + return false; + } + + // The string should be a host name (i.e., not an IP address). + return !preg_match('#^(.+\.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $string); + } + + /** + * Check if a cookie is valid for a given path + * + * From the path-match check in RFC 6265 section 5.1.4 + * + * @param string $request_path Path to check + * @return boolean Whether the cookie is valid for the given path + */ + public function path_matches($request_path) { + if (empty($request_path)) { + // Normalize empty path to root + $request_path = '/'; + } + + if (!isset($this->attributes['path'])) { + // Cookies created manually; cookies created by Requests will set + // the path to the requested path + return true; + } + + $cookie_path = $this->attributes['path']; + + if ($cookie_path === $request_path) { + // The cookie-path and the request-path are identical. + return true; + } + + if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) { + if (substr($cookie_path, -1) === '/') { + // The cookie-path is a prefix of the request-path, and the last + // character of the cookie-path is %x2F ("/"). + return true; + } + + if (substr($request_path, strlen($cookie_path), 1) === '/') { + // The cookie-path is a prefix of the request-path, and the + // first character of the request-path that is not included in + // the cookie-path is a %x2F ("/") character. + return true; + } + } + + return false; + } + + /** + * Normalize cookie and attributes + * + * @return boolean Whether the cookie was successfully normalized + */ + public function normalize() { + foreach ($this->attributes as $key => $value) { + $orig_value = $value; + $value = $this->normalize_attribute($key, $value); + if ($value === null) { + unset($this->attributes[$key]); + continue; + } + + if ($value !== $orig_value) { + $this->attributes[$key] = $value; + } + } + + return true; + } + + /** + * Parse an individual cookie attribute + * + * Handles parsing individual attributes from the cookie values. + * + * @param string $name Attribute name + * @param string|boolean $value Attribute value (string value, or true if empty/flag) + * @return mixed Value if available, or null if the attribute value is invalid (and should be skipped) + */ + protected function normalize_attribute($name, $value) { + switch (strtolower($name)) { + case 'expires': + // Expiration parsing, as per RFC 6265 section 5.2.1 + if (is_int($value)) { + return $value; + } + + $expiry_time = strtotime($value); + if ($expiry_time === false) { + return null; + } + + return $expiry_time; + + case 'max-age': + // Expiration parsing, as per RFC 6265 section 5.2.2 + if (is_int($value)) { + return $value; + } + + // Check that we have a valid age + if (!preg_match('/^-?\d+$/', $value)) { + return null; + } + + $delta_seconds = (int) $value; + if ($delta_seconds <= 0) { + $expiry_time = 0; + } + else { + $expiry_time = $this->reference_time + $delta_seconds; + } + + return $expiry_time; + + case 'domain': + // Domains are not required as per RFC 6265 section 5.2.3 + if (empty($value)) { + return null; + } + + // Domain normalization, as per RFC 6265 section 5.2.3 + if ($value[0] === '.') { + $value = substr($value, 1); + } + + return $value; + + default: + return $value; + } + } + + /** + * Format a cookie for a Cookie header + * + * This is used when sending cookies to a server. + * + * @return string Cookie formatted for Cookie header + */ + public function format_for_header() { + return sprintf('%s=%s', $this->name, $this->value); + } + + /** + * Format a cookie for a Cookie header + * + * @codeCoverageIgnore + * @deprecated Use {@see Requests_Cookie::format_for_header} + * @return string + */ + public function formatForHeader() { + return $this->format_for_header(); + } + + /** + * Format a cookie for a Set-Cookie header + * + * This is used when sending cookies to clients. This isn't really + * applicable to client-side usage, but might be handy for debugging. + * + * @return string Cookie formatted for Set-Cookie header + */ + public function format_for_set_cookie() { + $header_value = $this->format_for_header(); + if (!empty($this->attributes)) { + $parts = array(); + foreach ($this->attributes as $key => $value) { + // Ignore non-associative attributes + if (is_numeric($key)) { + $parts[] = $value; + } + else { + $parts[] = sprintf('%s=%s', $key, $value); + } + } + + $header_value .= '; ' . implode('; ', $parts); + } + return $header_value; + } + + /** + * Format a cookie for a Set-Cookie header + * + * @codeCoverageIgnore + * @deprecated Use {@see Requests_Cookie::format_for_set_cookie} + * @return string + */ + public function formatForSetCookie() { + return $this->format_for_set_cookie(); + } + + /** + * Get the cookie value + * + * Attributes and other data can be accessed via methods. + */ + public function __toString() { + return $this->value; + } + + /** + * Parse a cookie string into a cookie object + * + * Based on Mozilla's parsing code in Firefox and related projects, which + * is an intentional deviation from RFC 2109 and RFC 2616. RFC 6265 + * specifies some of this handling, but not in a thorough manner. + * + * @param string Cookie header value (from a Set-Cookie header) + * @return Requests_Cookie Parsed cookie object + */ + public static function parse($string, $name = '', $reference_time = null) { + $parts = explode(';', $string); + $kvparts = array_shift($parts); + + if (!empty($name)) { + $value = $string; + } + elseif (strpos($kvparts, '=') === false) { + // Some sites might only have a value without the equals separator. + // Deviate from RFC 6265 and pretend it was actually a blank name + // (`=foo`) + // + // https://bugzilla.mozilla.org/show_bug.cgi?id=169091 + $name = ''; + $value = $kvparts; + } + else { + list($name, $value) = explode('=', $kvparts, 2); + } + $name = trim($name); + $value = trim($value); + + // Attribute key are handled case-insensitively + $attributes = new Requests_Utility_CaseInsensitiveDictionary(); + + if (!empty($parts)) { + foreach ($parts as $part) { + if (strpos($part, '=') === false) { + $part_key = $part; + $part_value = true; + } + else { + list($part_key, $part_value) = explode('=', $part, 2); + $part_value = trim($part_value); + } + + $part_key = trim($part_key); + $attributes[$part_key] = $part_value; + } + } + + return new Requests_Cookie($name, $value, $attributes, array(), $reference_time); + } + + /** + * Parse all Set-Cookie headers from request headers + * + * @param Requests_Response_Headers $headers Headers to parse from + * @param Requests_IRI|null $origin URI for comparing cookie origins + * @param int|null $time Reference time for expiration calculation + * @return array + */ + public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) { + $cookie_headers = $headers->getValues('Set-Cookie'); + if (empty($cookie_headers)) { + return array(); + } + + $cookies = array(); + foreach ($cookie_headers as $header) { + $parsed = self::parse($header, '', $time); + + // Default domain/path attributes + if (empty($parsed->attributes['domain']) && !empty($origin)) { + $parsed->attributes['domain'] = $origin->host; + $parsed->flags['host-only'] = true; + } + else { + $parsed->flags['host-only'] = false; + } + + $path_is_valid = (!empty($parsed->attributes['path']) && $parsed->attributes['path'][0] === '/'); + if (!$path_is_valid && !empty($origin)) { + $path = $origin->path; + + // Default path normalization as per RFC 6265 section 5.1.4 + if (substr($path, 0, 1) !== '/') { + // If the uri-path is empty or if the first character of + // the uri-path is not a %x2F ("/") character, output + // %x2F ("/") and skip the remaining steps. + $path = '/'; + } + elseif (substr_count($path, '/') === 1) { + // If the uri-path contains no more than one %x2F ("/") + // character, output %x2F ("/") and skip the remaining + // step. + $path = '/'; + } + else { + // Output the characters of the uri-path from the first + // character up to, but not including, the right-most + // %x2F ("/"). + $path = substr($path, 0, strrpos($path, '/')); + } + $parsed->attributes['path'] = $path; + } + + // Reject invalid cookie domains + if (!empty($origin) && !$parsed->domain_matches($origin->host)) { + continue; + } + + $cookies[$parsed->name] = $parsed; + } + + return $cookies; + } + + /** + * Parse all Set-Cookie headers from request headers + * + * @codeCoverageIgnore + * @deprecated Use {@see Requests_Cookie::parse_from_headers} + * @return string + */ + public static function parseFromHeaders(Requests_Response_Headers $headers) { + return self::parse_from_headers($headers); + } +} diff --git a/srcs/wordpress/wp-includes/Requests/Cookie/Jar.php b/srcs/wordpress/wp-includes/Requests/Cookie/Jar.php new file mode 100644 index 0000000..69be0fb --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Cookie/Jar.php @@ -0,0 +1,175 @@ +cookies = $cookies; + } + + /** + * Normalise cookie data into a Requests_Cookie + * + * @param string|Requests_Cookie $cookie + * @return Requests_Cookie + */ + public function normalize_cookie($cookie, $key = null) { + if ($cookie instanceof Requests_Cookie) { + return $cookie; + } + + return Requests_Cookie::parse($cookie, $key); + } + + /** + * Normalise cookie data into a Requests_Cookie + * + * @codeCoverageIgnore + * @deprecated Use {@see Requests_Cookie_Jar::normalize_cookie} + * @return Requests_Cookie + */ + public function normalizeCookie($cookie, $key = null) { + return $this->normalize_cookie($cookie, $key); + } + + /** + * Check if the given item exists + * + * @param string $key Item key + * @return boolean Does the item exist? + */ + public function offsetExists($key) { + return isset($this->cookies[$key]); + } + + /** + * Get the value for the item + * + * @param string $key Item key + * @return string Item value + */ + public function offsetGet($key) { + if (!isset($this->cookies[$key])) { + return null; + } + + return $this->cookies[$key]; + } + + /** + * Set the given item + * + * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`) + * + * @param string $key Item name + * @param string $value Item value + */ + public function offsetSet($key, $value) { + if ($key === null) { + throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); + } + + $this->cookies[$key] = $value; + } + + /** + * Unset the given header + * + * @param string $key + */ + public function offsetUnset($key) { + unset($this->cookies[$key]); + } + + /** + * Get an iterator for the data + * + * @return ArrayIterator + */ + public function getIterator() { + return new ArrayIterator($this->cookies); + } + + /** + * Register the cookie handler with the request's hooking system + * + * @param Requests_Hooker $hooks Hooking system + */ + public function register(Requests_Hooker $hooks) { + $hooks->register('requests.before_request', array($this, 'before_request')); + $hooks->register('requests.before_redirect_check', array($this, 'before_redirect_check')); + } + + /** + * Add Cookie header to a request if we have any + * + * As per RFC 6265, cookies are separated by '; ' + * + * @param string $url + * @param array $headers + * @param array $data + * @param string $type + * @param array $options + */ + 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); + } + } + + /** + * Parse all cookies from a response and attach them to the response + * + * @var Requests_Response $response + */ + public function before_redirect_check(Requests_Response &$return) { + $url = $return->url; + if (!$url instanceof Requests_IRI) { + $url = new Requests_IRI($url); + } + + $cookies = Requests_Cookie::parse_from_headers($return->headers, $url); + $this->cookies = array_merge($this->cookies, $cookies); + $return->cookies = $this; + } +} \ No newline at end of file diff --git a/srcs/wordpress/wp-includes/Requests/Exception.php b/srcs/wordpress/wp-includes/Requests/Exception.php new file mode 100644 index 0000000..37d4711 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Exception.php @@ -0,0 +1,62 @@ +type = $type; + $this->data = $data; + } + + /** + * Like {@see getCode()}, but a string code. + * + * @codeCoverageIgnore + * @return string + */ + public function getType() { + return $this->type; + } + + /** + * Gives any relevant data + * + * @codeCoverageIgnore + * @return mixed + */ + public function getData() { + return $this->data; + } +} \ No newline at end of file diff --git a/srcs/wordpress/wp-includes/Requests/Exception/HTTP.php b/srcs/wordpress/wp-includes/Requests/Exception/HTTP.php new file mode 100644 index 0000000..9ac6a87 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Exception/HTTP.php @@ -0,0 +1,71 @@ +reason = $reason; + } + + $message = sprintf('%d %s', $this->code, $this->reason); + parent::__construct($message, 'httpresponse', $data, $this->code); + } + + /** + * Get the status message + */ + public function getReason() { + return $this->reason; + } + + /** + * Get the correct exception class for a given error code + * + * @param int|bool $code HTTP status code, or false if unavailable + * @return string Exception class name to use + */ + public static function get_class($code) { + if (!$code) { + return 'Requests_Exception_HTTP_Unknown'; + } + + $class = sprintf('Requests_Exception_HTTP_%d', $code); + if (class_exists($class)) { + return $class; + } + + return 'Requests_Exception_HTTP_Unknown'; + } +} \ No newline at end of file diff --git a/srcs/wordpress/wp-includes/Requests/Exception/HTTP/304.php b/srcs/wordpress/wp-includes/Requests/Exception/HTTP/304.php new file mode 100644 index 0000000..6799033 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Exception/HTTP/304.php @@ -0,0 +1,27 @@ +code = $data->status_code; + } + + parent::__construct($reason, $data); + } +} \ No newline at end of file diff --git a/srcs/wordpress/wp-includes/Requests/Exception/Transport.php b/srcs/wordpress/wp-includes/Requests/Exception/Transport.php new file mode 100644 index 0000000..e60b488 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Exception/Transport.php @@ -0,0 +1,5 @@ +type = $type; + } + + if ($code !== null) { + $this->code = $code; + } + + if ($message !== null) { + $this->reason = $message; + } + + $message = sprintf('%d %s', $this->code, $this->reason); + parent::__construct($message, $this->type, $data, $this->code); + } + + /** + * Get the error message + */ + public function getReason() { + return $this->reason; + } + +} diff --git a/srcs/wordpress/wp-includes/Requests/Hooker.php b/srcs/wordpress/wp-includes/Requests/Hooker.php new file mode 100644 index 0000000..f667ae9 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Hooker.php @@ -0,0 +1,33 @@ +0 is executed later + */ + public function register($hook, $callback, $priority = 0); + + /** + * Dispatch a message + * + * @param string $hook Hook name + * @param array $parameters Parameters to pass to callbacks + * @return boolean Successfulness + */ + public function dispatch($hook, $parameters = array()); +} \ No newline at end of file diff --git a/srcs/wordpress/wp-includes/Requests/Hooks.php b/srcs/wordpress/wp-includes/Requests/Hooks.php new file mode 100644 index 0000000..2e61c73 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/Hooks.php @@ -0,0 +1,68 @@ +0 is executed later + */ + public function register($hook, $callback, $priority = 0) { + if (!isset($this->hooks[$hook])) { + $this->hooks[$hook] = array(); + } + if (!isset($this->hooks[$hook][$priority])) { + $this->hooks[$hook][$priority] = array(); + } + + $this->hooks[$hook][$priority][] = $callback; + } + + /** + * Dispatch a message + * + * @param string $hook Hook name + * @param array $parameters Parameters to pass to callbacks + * @return boolean Successfulness + */ + public function dispatch($hook, $parameters = array()) { + if (empty($this->hooks[$hook])) { + return false; + } + + foreach ($this->hooks[$hook] as $priority => $hooked) { + foreach ($hooked as $callback) { + call_user_func_array($callback, $parameters); + } + } + + return true; + } +} \ No newline at end of file diff --git a/srcs/wordpress/wp-includes/Requests/IDNAEncoder.php b/srcs/wordpress/wp-includes/Requests/IDNAEncoder.php new file mode 100644 index 0000000..ebbe211 --- /dev/null +++ b/srcs/wordpress/wp-includes/Requests/IDNAEncoder.php @@ -0,0 +1,388 @@ +