WpOrg\Requests
Requests::set_defaults
Set the default values
The $options parameter is updated with the results.
Method of the class: Requests{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = Requests::set_defaults( $url, $headers, $data, $type, $options );
- $url(string) (required) (passed by reference — &)
- URL to request.
- $headers(array) (required) (passed by reference — &)
- Extra headers to send with the request.
- $data(array|null) (required) (passed by reference — &)
- Data to send either as a query string for GET/HEAD requests, or in the body for POST requests.
- $type(string) (required) (passed by reference — &)
- HTTP request type.
- $options(array) (required) (passed by reference — &)
- Options for the request.
Requests::set_defaults() Requests::set defaults code WP 7.0
protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) {
if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) {
throw new Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url);
}
if (empty($options['hooks'])) {
$options['hooks'] = new Hooks();
}
if (is_array($options['auth'])) {
$options['auth'] = new Basic($options['auth']);
}
if ($options['auth'] !== false) {
$options['auth']->register($options['hooks']);
}
if (is_string($options['proxy']) || is_array($options['proxy'])) {
$options['proxy'] = new Http($options['proxy']);
}
if ($options['proxy'] !== false) {
$options['proxy']->register($options['hooks']);
}
if (is_array($options['cookies'])) {
$options['cookies'] = new Jar($options['cookies']);
} elseif (empty($options['cookies'])) {
$options['cookies'] = new Jar();
}
if ($options['cookies'] !== false) {
$options['cookies']->register($options['hooks']);
}
if ($options['idn'] !== false) {
$iri = new Iri($url);
$iri->host = IdnaEncoder::encode($iri->ihost);
$url = $iri->uri;
}
// Massage the type to ensure we support it.
$type = strtoupper($type);
if (!isset($options['data_format'])) {
if (in_array($type, [self::HEAD, self::GET, self::DELETE], true)) {
$options['data_format'] = 'query';
} else {
$options['data_format'] = 'body';
}
}
}