public static function attachOriginHeader($response, $origin)
	{
		if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
			$response->headers->set('Access-Control-Allow-Origin', $origin);
			return true;
		}
		
		if ('*' == config('api.cors_allowed_origin', 'client')) {
			$response->headers->set('Access-Control-Allow-Origin', '*');
			return true;
		}
		
		if ('client' == config('api.cors_allowed_origin', 'client')) {
			$client = Authentication::instance()->client();
			if (empty($client) || empty($client->endpoints())) {
				return false;
			}
			
			foreach ($client->endpoints() as $endpoint) {
				$parts = parse_url($endpoint);
				if (empty($parts['scheme']) || empty($parts['host'])) {
					continue;
				}
				
				$port = '';
				if (array_get($parts, 'port')) {
					$port = ':' . array_get($parts, 'port');
				}
				
				$url = $parts['scheme'] . '://' . $parts['host'] . $port;
				
				if ($origin == $url) {
					$response->headers->set('Access-Control-Allow-Origin', $url);
					return true;
				}
			}
		}
		
		return false;
	}