/** * Test get messages for code * * Pre-conditions: * Case A: Status = 200 * Case B: Status = 304 * Case C: Status = 420 //Fake * * Post-conditions: * Case A: Message = '200 OK' * Case B: Message = '304 Not Modified' * Case C: Message = NULL */ public function testGetMessageForCode() { //Case A $this->assertEquals('200 OK', Slim_Http_Response::getMessageForCode(200)); //Case B $this->assertEquals('304 Not Modified', Slim_Http_Response::getMessageForCode(304)); //Case C $this->assertNull(Slim_Http_Response::getMessageForCode(420)); }
/** * Run * * This method invokes the middleware stack, including the core Slim application; * the result is an array of HTTP status, header, and body. These three items * are returned to the HTTP client. * * @return void */ public function run() { //Apply final outer middleware layers $this->add(new Slim_Middleware_PrettyExceptions()); //Invoke middleware and application stack $this->middleware[0]->call(); //Fetch status, header, and body list($status, $header, $body) = $this->response->finalize(); //Send headers if (headers_sent() === false) { //Send status if (strpos(PHP_SAPI, 'cgi') === 0) { header(sprintf('Status: %s', Slim_Http_Response::getMessageForCode($status))); } else { header(sprintf('HTTP/%s %s', $this->config('http.version'), Slim_Http_Response::getMessageForCode($status))); } //Send headers foreach ($header as $name => $value) { $hValues = explode("\n", $value); foreach ($hValues as $hVal) { header("{$name}: {$hVal}", false); } } } //Send body echo $body; }
/** * Test message for code when message exists */ public function testMessageForCodeWithInvalidCode() { $this->assertNull(Slim_Http_Response::getMessageForCode(600)); }
/** * Run * * This method invokes the middleware stack, including the core Slim application; * the result is an array of HTTP status, header, and body. These three items * are returned to the HTTP client. * * @return void */ public function run() { //Fetch status, header, and body list($status, $header, $body) = $this->middleware[0]->call($this->environment); //Send status if (strpos(PHP_SAPI, 'cgi') === 0) { header(sprintf('Status: %s', Slim_Http_Response::getMessageForCode($status))); } else { header(sprintf('HTTP/%s %s', $this->config('http.version'), Slim_Http_Response::getMessageForCode($status))); } //Send header foreach ($header as $name => $value) { $hValues = explode("\n", $value); foreach ($hValues as $hVal) { header("{$name}: {$hVal}", false); } } //Send body if (is_string($body)) { echo $body; } else { $body->process(); } }