/** * Halt * * Stop the application and immediately send the response with a * specific status and body to the HTTP client. This may send any * type of response: info, success, redirect, client error, or server error. * If you need to render a template AND customize the response status, * use Slim::render() instead. * * @param int $status The HTTP response status * @param string $message The HTTP response body * @return void */ public function halt($status, $message = '') { $this->cleanBuffer(); $this->response->status($status); $this->response->body($message); $this->stop(); }
/** * Halt * * Halt the application and immediately send an HTTP response with a * specific status code and body. This may be used to send any type of * response: info, success, redirect, client error, or server error. * If you need to render a template AND customize the response status, * you should use Slim::render() instead. * * @param int $status The HTTP response status * @param string $message The HTTP response body * @return void */ public function halt($status, $message = '') { if (ob_get_level() !== 0) { ob_clean(); } $this->response->status($status); $this->response->body($message); $this->stop(); }
/** * Test finalize * * Pre-conditions: * Case A: Response status is 200 * Case B: Response status is 204 * Case C: Response status is 304 * * Post-conditions: * Case A: Response has body and content-length * Case B: Response does not have body and content-length * Case C: Response does not have body and content-length */ public function testFinalize() { //Case A $r1 = new Slim_Http_Response(new Slim_Http_Request()); $r1->body('body1'); $r1->finalize(); $this->assertEquals('body1', $r1->body()); $this->assertEquals(5, $r1->header('Content-Length')); //Case B $r2 = new Slim_Http_Response(new Slim_Http_Request()); $r2->body('body2'); $r2->status(204); $r2->finalize(); $this->assertEquals('', $r2->body()); $this->assertNull($r2->header('Content-Type')); //Case C $r3 = new Slim_Http_Response(new Slim_Http_Request()); $r3->body('body3'); $r3->status(304); $r3->finalize(); $this->assertEquals('', $r3->body()); $this->assertNull($r3->header('Content-Type')); }
/** * Test write for replacing */ public function testWriteReplace() { $r = new Slim_Http_Response('Foo'); $r->write('Bar', true); $this->assertEquals('Bar', $r->body()); }
/** * Test response body if HEAD request * * Pre-conditions: * HTTP method is HEAD * * Post-conditions: * Response body is NOT set; * Response headers are set; */ function testResponseBodyIfHeadRequest() { $this->expectOutputString(''); $_SERVER['REQUEST_METHOD'] = 'HEAD'; $req = new Slim_Http_Request(); $res = new Slim_Http_Response($req); $res->body('This is a test body'); $res->send(); $this->assertEquals('text/html', $res->header('Content-Type')); $this->assertEquals(19, $res->header('Content-Length')); }