function testSendCookies() { $cookie = new Cookie("name", "value"); $this->response->addCookie($cookie); $this->request->mock(); $this->send(); $expected = array("HTTP/1.1 200 OK", "Date: " . $this->response->getHeader("Date"), "Content-Length: 0", "Set-Cookie: " . $cookie); $this->assertEquals($expected, HeaderStack::stack()); }
/** * Provides a minimal default not found response, emitting a HTTP Status 404 * and writing "Not Found" to the User Agent. * * @param Request $request * @param Response $response * @return void */ public function defaultNotFound(Request $request, Response $response) { $response->html("<b>Not Found</b>", 404); }
function testNoCacheControlWhenEmpty() { $this->cacheControl->makeCacheHeaders(); $this->assertNull($this->response->getHeader("Cache-Control")); }
function testIsBodyAllowed() { $response = new Response(); $this->assertTrue($response->isBodyAllowed()); $response->setStatus(101); $this->assertFalse($response->isBodyAllowed()); $response->setStatus(204); $this->assertFalse($response->isBodyAllowed()); $response->setStatus(304); $this->assertFalse($response->isBodyAllowed()); }
function testMethodNotAllowedDispatch() { $this->request->mock(array("REQUEST_URI" => "/route-1", "REQUEST_METHOD" => "POST")); $this->assertEmpty($this->dispatch()); $this->assertEquals(405, $this->response->getStatus()); }
/** * Responds to the client to confirm method not allowed. * * @param \stdClass $match * @return void */ protected function routeToNotAllowed($match) { $status = $this->request->getMethod() === "OPTIONS" ? 200 : 405; $this->response->setHeader("Allow", join(", ", $match->allowed)); $this->response->setStatus($status); }
function fail(Request $request, Response $response) { $response->setBody("failed"); return false; }