Returns a 201 response with a Location header

@param string $url
@return Response
341042
protected function location($url)
    {
        /** @var $response Response */
        $response = $this->getResponse();

        $response->getHeaders()
            ->addHeaderLine(
                'Location',
                $url
            );

        $response->setStatusCode(201);

        return $response;
    }
675200
public static function getHeaderFromUrl($url) {
		// @codingStandardsIgnoreStart
		$url = @parse_url($url);
		// @codingStandardsIgnoreEnd
		if (empty($url)) {
			return false;
		}

		$url = array_map('trim', $url);
		$url['port'] = (!isset($url['port'])) ? '' : (':' . (int)$url['port']);
		$path = (isset($url['path'])) ? $url['path'] : '';

		if (empty($path)) {
			$path = '/';
		}

		$path .= (isset($url['query'])) ? "?$url[query]" : '';

		$defaults = [
			'http' => [
				'header' => "Accept: text/html\r\n" .
					"Connection: Close\r\n" .
					"User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64)\r\n",
			]
		];
		stream_context_get_default($defaults);

		if (isset($url['host']) && $url['host'] !== gethostbyname($url['host'])) {
			$url = "$url[scheme]://$url[host]$url[port]$path";
			$headers = get_headers($url);
			if (is_array($headers)) {
				return $headers;
			}
		}
		return false;
	}
995356
protected function getResponse($url, array $headers = []): ResponseInterface
    {
        return $this->httpClient->sendRequest($this->buildRequest($url, $headers));
    }
661576
protected function getRemoteResponse($url, array $headers = [])
    {
        $fixedHeaders = ['connection' => 'close'];
        foreach($headers as $key => $header) {
            if (is_int($key)) {
                list($key, $header) = explode(':', $header);
            }
            $key = strtolower($key);
            if (in_array($key, ['cache-control', 'accept', 'user-agent', 'accept-encoding', 'accept-language'])) {
                if (is_array($header)) {
                    $fixedHeaders[$key] = implode('; ', $header);
                }
            }
        }

        $browser = new Browser();
        /** @var \Buzz\Message\Response $res */
        $res = $browser->get($url, $fixedHeaders);
        if ($res->isSuccessful()) {
            $response = new Response($res->getContent(), $res->getStatusCode());
            $headers = [];
            foreach($res->getHeaders() as $header) {
                if (0 < strpos($header, ':')) {
                    list($key, $value) = explode(':', $header);
                    $headers[trim($key)] = trim($value);
                }
            }
            $response->headers->add($headers);
            return $response;
        }

        return null;
    }
361706
protected static function _read( $url ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Could be used in classes extending this class.
		$headers  = array( 'Accept' => 'application/json' );
		$response = Utils\http_request(
			'GET',
			$url,
			null,
			$headers,
			array( 'timeout' => 30 )
		);
		if ( 200 === $response->status_code ) {
			return $response->body;
		}
		WP_CLI::error( "Couldn't fetch response from {$url} (HTTP code {$response->status_code})." );
	}
991018
protected function fetchUrl(string $url): string
    {
        $curl = curl_init($url);
        curl_setopt_array($curl, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => $this->timeOut
        ]);
        $data = curl_exec($curl);
        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $error = curl_error($curl);
        curl_close($curl);

        if ($error) {
            throw new FetchFailedException(sprintf("A cURL error occurred for \"%s\": %s", $url, $error));
        }

        if ($statusCode !== 200) {
            throw new FetchFailedException(sprintf("URL \"%s\" responded with status code %d.", $url, $statusCode));
        }

        if (!$data) {
            throw new FetchFailedException(sprintf("URL \"%s\" returned no data.", $url));
        }

        return $data;
    }
926124
public function request($url)
    {
        $params = $this->parameters;
        $data = $params->getPostList();
        $data['signature'] = $this->getSignature($data);
        $data['key'] = $params->getAuth('key');

        $url = $params->getAuth('apiHost') . $params->getAuth('apiVersion') .'/'. $url .'.'. $params->getAuth('apiFormat');
        $data = json_encode($data);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        if ($params->getAuth('disableSSLChecks')) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        }

        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Length: ' . mb_strlen($data),
            'Content-Type: application/json'
        ));

        if ($params->hasProxy()) {
            curl_setopt($ch, CURLOPT_PROXY, $params->getProxy());
        }

        $result = curl_exec($ch);
        $info = curl_getinfo($ch);
        $error = curl_error($ch);
        $errno = curl_errno($ch);

        curl_close($ch);

        if ($result === false && !empty($error)) {
            throw new NetworkException($error, $errno);
        }

        return $this->parseResponse($result, $info);
    }
1349425
protected function _send_get_request( $url ) {
		$response = $this->_send_request( $url, array( 'method' => 'GET' ) );
		
		$response_code = wp_remote_retrieve_response_code( $response );
		$this->assertEquals( 200, $response_code, 'The Mailtrap.io API resonse code is not equals to 200.' );

		return $response;
	}
231982
private function &getHandle($url, $headers)
    {
        $http = curl_init();

        curl_setopt($http, CURLOPT_USERAGENT, $this->getUserAgent());
        curl_setopt($http, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($http, CURLINFO_HEADER_OUT, true);
        curl_setopt($http, CURLOPT_URL, $url);

        if (!$this->getSslVerifyPeer()) {
            curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($http, CURLOPT_SSL_VERIFYHOST, false);
        }

        if (is_array($headers) && count($headers)) {
            curl_setopt($http, CURLOPT_HTTPHEADER, $headers);
        }

        $this->response_headers = [];

        curl_setopt(
            $http,
            CURLOPT_HEADERFUNCTION,
            function($curl, $header) {
                $len = strlen($header);
                $header = explode(':', $header, 2);

                if (count($header) < 2) {
                    return $len;
                }

                $name = strtolower(trim($header[0]));

                if (!array_key_exists($name, $this->response_headers)) {
                    $this->response_headers[$name] = [trim($header[1])];
                } else {
                    $this->response_headers[$name][] = trim($header[1]);
                }

                return $len;
            }
        );

        return $http;
    }
1012090
private function getFile($url)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		$result = curl_exec($ch);
		curl_close($ch);

		$response = json_decode($result, TRUE);
		if (is_array($response) && count($response) > 0 && (!isset($response['status']) || $response['status'] != '404')) {
			return $response;
		}
		
		return false;
	}
341316
protected function sendHeadAndGetResponse($url)
    {
        /** @var REST $rest */
        $rest = $this->getModule('REST');
        $rest->sendHEAD($url);

        return $rest->client->getInternalResponse();
    }
456490
public function created($location = null)
    {
        $this->respondWith(201);

        if (!empty($location)) {
            $this->setResponseHeader('Location', $location);
        }
    }
1128858
protected function extract(string $url):string {
		$this->initCurl();

		curl_setopt_array($this->curl, [
			CURLOPT_FOLLOWLOCATION => false
		]);

		$response = $this->getResponse($url);

		if(!$response instanceof ResponseInterface){
			return ''; // @codeCoverageIgnore
		}

		$info    = $response->info;
		$headers = $response->headers;

		// check curl_info()
		if(in_array($info->http_code, range(300, 308), true) && isset($info->redirect_url) && !empty($info->redirect_url)){
			return $info->redirect_url;
		}
		// look for a location header
		elseif(isset($headers->location) && !empty($headers->location)){
			return $headers->location; // @codeCoverageIgnore
		}

		return '';
	}
1336629
final protected function getRedirectResponse($location, $addSuffix = true)
    {
        $url = $this->request()->getAppUrl();
        $url .= $location;
        if ($addSuffix) {
            $url .= $this->request()->getSuffix();
        }
        return $this->getRedirectUrlResponse($url);
    }
292665
public function redirect($url)
    {
        $location = $this->_request->getBasePath();
        $location = str_replace('//', '/', "{$location}/{$url}");
        $this->_response->setStatusCode(302);
        $header = new GenericHeader('Location', $location);
        $this->_response->getHeaders()->addHeader($header);
        return $this->disableRendering();
    }
1135497
public static function call($url)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
        curl_setopt($ch, CURLOPT_TIMEOUT, 45);

        $result = curl_exec($ch);

        if (! $result) {
            throw new \Exception(sprintf('The endpoint "%s" is not returning anything.', $url));
        }

        return simplexml_load_string($result);
    }
145120
public static function get_http_response_code( $url ) {

		$curl = curl_init();
		curl_setopt_array(
			$curl,
			[
				CURLOPT_RETURNTRANSFER => true,
				CURLOPT_URL            => $url,
			]
		);
		curl_exec( $curl );
		$response_code = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
		curl_close( $curl );

		return $response_code;
	}