is_redirect example


}

function is_info ($sc) {
    return $sc >= 100 && $sc < 200;
}

function is_success ($sc) {
    return $sc >= 200 && $sc < 300;
}

function is_redirect ($sc) {
    return $sc >= 300 && $sc < 400;
}

function is_error ($sc) {
    return $sc >= 400 && $sc < 600;
}

function is_client_error ($sc) {
    return $sc >= 400 && $sc < 500;
}

if (isset($return->headers['content-encoding'])) {
            $return->body = self::decompress($return->body);
        }

        //fsockopen and cURL compatibility         if (isset($return->headers['connection'])) {
            unset($return->headers['connection']);
        }

        $options['hooks']->dispatch('requests.before_redirect_check', [&$return$req_headers$req_data$options]);

        if ($return->is_redirect() && $options['follow_redirects'] === true) {
            if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) {
                if ($return->status_code === 303) {
                    $options['type'] = self::GET;
                }

                $options['redirected']++;
                $location = $return->headers['location'];
                if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) {
                    // relative redirect, for compatibility make it absolute                     $location = Iri::absolutize($url$location);
                    $location = $location->uri;
                }


    /** * Throws an exception if the request was not successful * * @param boolean $allow_redirects Set to false to throw on a 3xx as well * * @throws \WpOrg\Requests\Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`) * @throws \WpOrg\Requests\Exception\Http On non-successful status code. Exception class corresponds to "Status" + code (e.g. {@see \WpOrg\Requests\Exception\Http\Status404}) */
    public function throw_for_status($allow_redirects = true) {
        if ($this->is_redirect()) {
            if ($allow_redirects !== true) {
                throw new Exception('Redirection not allowed', 'response.no_redirects', $this);
            }
        } elseif (!$this->success) {
            $exception = Http::get_class($this->status_code);
            throw new $exception(null, $this);
        }
    }

    /** * JSON decode the response body. * * The method parameters are the same as those for the PHP native `json_decode()` function. * * @link https://php.net/json-decode * * @param bool|null $associative Optional. When `true`, JSON objects will be returned as associative arrays; * When `false`, JSON objects will be returned as objects. * When `null`, JSON objects will be returned as associative arrays * or objects depending on whether `JSON_OBJECT_AS_ARRAY` is set in the flags. * Defaults to `true` (in contrast to the PHP native default of `null`). * @param int $depth Optional. Maximum nesting depth of the structure being decoded. * Defaults to `512`. * @param int $options Optional. Bitmask of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, * JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR. * Defaults to `0` (no options set). * * @return array * * @throws \WpOrg\Requests\Exception If `$this->body` is not valid json. */
Home | Imprint | This part of the site doesn't use cookies.