function testGetAbsoluteUrl() { $s = ['HTTP_HOST' => 'sabredav.org', 'REQUEST_URI' => '/foo']; $r = Sapi::createFromServerArray($s); $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUrl()); $s = ['HTTP_HOST' => 'sabredav.org', 'REQUEST_URI' => '/foo', 'HTTPS' => 'on']; $r = Sapi::createFromServerArray($s); $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUrl()); }
/** * @return bool */ public static function isLocal() { if (Sapi::isCli() === true) { return true; } if (Sapi::isPhpServer() === true) { return true; } if (isset($_SERVER['HTTP_CLIENT_IP']) || isset($_SERVER['HTTP_X_FORWARDED_FOR']) || !isset($_SERVER['REMOTE_ADDR'])) { return false; } return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']); }
/** * @runInSeparateProcess * * Unfortunately we have no way of testing if the HTTP response code got * changed. */ function testSend() { if (!function_exists('xdebug_get_headers')) { $this->markTestSkipped('XDebug needs to be installed for this test to run'); } $response = new Response(204, ['Content-Type', 'text/xml']); $response->setBody('foo'); ob_start(); Sapi::sendResponse($response); $headers = xdebug_get_headers(); $result = ob_get_clean(); header_remove(); $this->assertEquals(["0: Content-Type", "1: text/xml"], $headers); $this->assertEquals('foo', $result); }
/** * @runInSeparateProcess * * Unfortunately we have no way of testing if the HTTP response code got * changed. */ function testSend() { if (!function_exists('xdebug_get_headers')) { $this->markTestSkipped('XDebug needs to be installed for this test to run'); } $response = new Response(204, ['Content-Type' => 'text/xml;charset=UTF-8']); // Second Content-Type header. Normally this doesn't make sense. $response->addHeader('Content-Type', 'application/xml'); $response->setBody('foo'); ob_start(); Sapi::sendResponse($response); $headers = xdebug_get_headers(); $result = ob_get_clean(); header_remove(); $this->assertEquals(["Content-Type: text/xml;charset=UTF-8", "Content-Type: application/xml"], $headers); $this->assertEquals('foo', $result); }
/** * @runInSeparateProcess * @depends testSend */ function testSendLimitedByContentLengthStream() { $response = new Response(200, ['Content-Length' => 19]); $body = fopen('php://memory', 'w'); fwrite($body, 'Ignore this. Send this sentence. Ignore this too.'); rewind($body); fread($body, 13); $response->setBody($body); ob_start(); Sapi::sendResponse($response); $result = ob_get_clean(); header_remove(); $this->assertEquals('Send this sentence.', $result); }