Jar example



    /** * Normalizes cookies for using in Requests. * * @since 4.6.0 * * @param array $cookies Array of cookies to send with the request. * @return WpOrg\Requests\Cookie\Jar Cookie holder object. */
    public static function normalize_cookies( $cookies ) {
        $cookie_jar = new WpOrg\Requests\Cookie\Jar();

        foreach ( $cookies as $name => $value ) {
            if ( $value instanceof WP_Http_Cookie ) {
                $attributes                 = array_filter(
                    $value->get_attributes(),
                    static function( $attr ) {
                        return null !== $attr;
                    }
                );
                $cookie_jar[ $value->name ] = new WpOrg\Requests\Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
            } elseif ( is_scalar( $value ) ) {
                


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

    public $cookies = [];

    /** * Constructor */
    public function __construct() {
        $this->headers = new Headers();
        $this->cookies = new Jar();
    }

    /** * Is the response a redirect? * * @return boolean True if redirect (3xx status), false if not. */
    public function is_redirect() {
        $code = $this->status_code;
        return in_array($code[300, 301, 302, 303, 307], true) || $code > 307 && $code < 400;
    }

    
if (is_array($options) === false) {
            throw InvalidArgument::create(4, '$options', 'array', gettype($options));
        }

        $this->url     = $url;
        $this->headers = $headers;
        $this->data    = $data;
        $this->options = $options;

        if (empty($this->options['cookies'])) {
            $this->options['cookies'] = new Jar();
        }
    }

    /** * Get a property's value * * @param string $name Property name. * @return mixed|null Property value, null if none found */
    public function __get($name) {
        if (isset($this->options[$name])) {
            
Home | Imprint | This part of the site doesn't use cookies.