Check that requested URL is clean

@param \Shade\Request\Web $request Request

@throws \Shade\Exception

@return bool
481618
public function isRequestedUrlClean(Request\Web $request)
    {
        $server = $request->getServer();
        if (!isset($server['REQUEST_URI'])) {
            throw new Exception('REQUEST_URI is not set');
        }

        return strpos($server['REQUEST_URI'], $this->entryPoint) !== 0;
    }
531119
protected function isAllowed($request)
    {
        try {
            $decrypted = Crypt::decrypt($request->get('key'));
        } catch (DecryptException $e) {
            $decrypted = '';
        }

        return $decrypted == 'opcache' || in_array($this->getRequestIp($request), [$this->getServerIp(), '127.0.0.1', '::1']);
    }
617798
protected function shouldPassThrough($request)
    {
        foreach ($this->except as $except) {
            if ($request->is($except)) {
                return true;
            }
        }
        return false;
    }
14609
public function execute($request)
    {
        $result = $request->authHeaders()->send();

        if ($result->status === self::API_STATUS_FAIL) {
            throw new Exception('Error: '.$result->error);
        }

        return $result;
    }
1093232
protected static function checkServerPort(Request $request): bool
    {
        return $request->server->has('SERVER_PORT') && self::HTTPS === (int)$request->server->get('SERVER_PORT');
    }
934611
public function isValid (Request $request)
		{
			$parsed = $this->parseRouteRequest($request);

			return $this->getBaseUri($request) !== null
				&& preg_match('#^' . preg_quote(rtrim($this->getBaseUri($request), '/'), '#') . '#', rtrim($request->getUri(false), '/'))
				&& $this->getController($request)->respondsTo($parsed['method'], $parsed['arguments']);
		}
646789
public function validateRequestHandshake(
        $request
    ) {
        if (!$request) {
            return false;
        }

        list($request, $headers) = $this->getRequestHeaders($request);
        // make a copy of the headers array to store all extra headers
        $extraHeaders = $headers;

        // parse the resulting url to separate query parameters from the path
        $url = parse_url($this->validateRequestLine($request));
        $path = isset($url['path']) ? $url['path'] : null;
        $urlParams = [];
        if (isset($url['query'])) {
            parse_str($url['query'], $urlParams);
        }

        if (empty($headers[self::HEADER_ORIGIN])) {
            throw new BadRequestException('No origin header');
        } else {
            unset($extraHeaders[self::HEADER_ORIGIN]);
        }

        $origin = $headers[self::HEADER_ORIGIN];

        if (!isset($headers[self::HEADER_UPGRADE])
            || strtolower($headers[self::HEADER_UPGRADE]) != self::UPGRADE_VALUE
        ) {
            throw new BadRequestException('Invalid upgrade header');
        } else {
            unset($extraHeaders[self::HEADER_UPGRADE]);
        }

        if (!isset($headers[self::HEADER_CONNECTION])
            || stripos($headers[self::HEADER_CONNECTION], self::CONNECTION_VALUE) === false
        ) {
            throw new BadRequestException('Invalid connection header');
        } else {
            unset($extraHeaders[self::HEADER_CONNECTION]);
        }

        if (!isset($headers[self::HEADER_HOST])) {
            // @todo Validate host == listening socket? Or would that break
            //        TCP proxies?
            throw new BadRequestException('No host header');
        } else {
            unset($extraHeaders[self::HEADER_HOST]);
        }

        if (!isset($headers[self::HEADER_VERSION])) {
            throw new BadRequestException('No version header received on handshake request');
        }

        if (!$this->acceptsVersion($headers[self::HEADER_VERSION])) {
            throw new BadRequestException('Unsupported version: ' . $headers[self::HEADER_VERSION]);
        } else {
            unset($extraHeaders[self::HEADER_VERSION]);
        }

        if (!isset($headers[self::HEADER_KEY])) {
            throw new BadRequestException('No key header received');
        }

        $key = trim($headers[self::HEADER_KEY]);

        if (!$key) {
            throw new BadRequestException('Invalid key');
        } else {
            unset($extraHeaders[self::HEADER_KEY]);
        }

        // Optional
        $protocol = null;
        if (isset($headers[self::HEADER_PROTOCOL])) {
            $protocol = $headers[self::HEADER_PROTOCOL];
            unset($extraHeaders[self::HEADER_PROTOCOL]);
        }

        $extensions = [];
        if (!empty($headers[self::HEADER_EXTENSIONS])) {
            $extensions = $headers[self::HEADER_EXTENSIONS];
            if (is_scalar($extensions)) {
                $extensions = [$extensions];
            }
        }
        unset($extraHeaders[self::HEADER_EXTENSIONS]);

        return [$path, $origin, $key, $extensions, $protocol, $extraHeaders, $urlParams];
    }
630250
protected function checkRequest($request)
    {
        if ($request['status_code'] === 200 || $request['status_code'] === 201) {
            return true;
        }

        $messages = array(
            204 => 'No content',
            400 => 'Bad Request',
            401 => 'Unauthorized',
            404 => 'Not Found',
            405 => 'Method Not Allowed',
            500 => 'Internal Server Error',
        );

        if (isset($messages[$request['status_code']])) {
            $xml = null;
            if ($request['response']) {
                $xml = $this->parseXML($request['response'], true);
            }

            throw new PrestashopWebServiceRequestException($messages[$request['status_code']], $request['status_code'], $xml);
        } else {
            $exception = 'This call to PrestaShop Web Services returned an unexpected HTTP status of: ';
            $exception.= $request['status_code'];
            throw new PrestashopWebServiceException($exception);
        }
    }
1047233
public function check(Request $request)
    {
        /** @var $response \Bolt\Storage\Database\Schema\SchemaCheck */
        $check = $this->app['schema']->check();

        $context = [
            'changes' => null,
            'check'   => $check,
            'debug'   => $request->query->has('debug'),
            'alters'  => $this->app['schema.comparator']->getAlters(),
            'creates' => $this->app['schema.comparator']->getCreates(),
            'diffs'   => $this->app['schema.comparator']->getDiffs(),
        ];

        return $this->render('@bolt/dbcheck/dbcheck.twig', $context);
    }
83420
public static function canBeUsedForRequest(Request $request)
    {
        return $request->has(self::CHUNK_NUMBER_INDEX) && $request->has(self::TOTAL_CHUNKS_INDEX) &&
            $request->has(self::CHUNK_UUID_INDEX);
    }
735586
protected function getAbsoluteUrl($request)
        {
            $request = ltrim($request);

            if (strpos($request, 'http') === 0) {
                return $request;
            }

            return $this->apiUrl . $request;
        }
1367353
protected function shouldPassThrough($request)
    {
        $excepts = [
            admin_base_path('auth/login'),
            admin_base_path('auth/logout'),
        ];

        foreach ($excepts as $except) {
            if ('/' !== $except) {
                $except = trim($except, '/');
            }

            if ($request->is($except)) {
                return true;
            }
        }

        return false;
    }
838655
public function allow(Request $request)
    {
        foreach ($this->patterns as $regex)
            if (preg_match(sprintf("#^%s$#i", $regex), $request->getUri()->getPath()))
                return false;

        return true;
    }
389157
protected function detectEnvFromUrlPath(IHttpRequest $request) {
        $env = $request->getUrl()->parse('/env={env}')->get('env');

        if ($env) {
            // remove environment from the url
            $cleanPath = str_replace(s('/env=%s', $env), '', $request->getUrl()->getPath());
            $request->getUrl()->setPath($cleanPath);
        }

        return $env;
    }
822475
public function checkAtLeastOneUrl($urls)
    {
        $urls = $this->cleanParameterUrls($urls);

        if (!is_array($urls)
            || count($urls) == 0
        ) {
            throw new Exception(Piwik::translate('SitesManager_ExceptionNoUrl'));
        }
    }
107063
public function cleanTrash()
	{
		$response = $this->send(new Request($this->uri->withPath($this->uri->getPath().'trash/resources'), 'DELETE'));

		if ($response->getStatusCode() == 204)
		{
			$response = json_decode($response->getBody(), true);

			if ( ! empty($response['operation']))
			{
				return $response['operation'];
			}

			return true;
		}

		return false;
	}
163204
public static function useHttps(Request $request): bool
    {
        $checks = [
            'HTTPS',
            'SERVER_PORT',
            'HTTP_X_FORWARDED_SSL',
            'HTTP_X_FORWARDED_PROTO',
        ];
        foreach ($checks as $check) {
            if (call_user_func([__CLASS__, sprintf('check%s', Text::toCamelCase($check))], $request)) {
                return true;
            }
        }

        return false;
    }