/** * {@inheritdoc} */ public function send(Request $request, Response $response) { // Set status and location header $response->status($this->status); $response->header('Location', $this->location); // Send headers $response->sendHeaders(); }
/** * {@inheritdoc} */ public function handle($showDetails = true) { // Should we return JSON? if (($returnAsJson = $this->returnAsJson()) === true) { $this->response->type('application/json'); } // Set the response body if ($showDetails) { $this->response->body($this->getDetailedError($returnAsJson)); } else { $this->response->body($this->getGenericError($returnAsJson)); } // Send the response along with appropriate headers if ($this->exception instanceof RequestException) { $status = $this->exception->getCode(); if ($this->exception instanceof MethodNotAllowedException) { $this->response->header('allows', implode(',', $this->exception->getAllowedMethods())); } } else { $status = 500; } $this->response->status($status)->send(); // Return false to stop further error handling return false; }
/** * Logs the user out. * * @access public */ public function logout() { $this->session->regenerateId(); $this->session->remove($this->authKey); $this->response->deleteCookie($this->authKey, $this->cookieOptions); $this->user = null; }
/** * Destroys the session. * * @access public */ public function destroy() { if (!$this->started) { throw new LogicException(vsprintf("%s(): The session has not been started yet.", [__METHOD__])); } $this->store->delete($this->sessionId); $this->response->deleteCookie($this->cookieName, $this->cookieOptions); $this->destroyed = true; }
/** * {@inheritdoc} */ public function send(Request $request, Response $response) { $this->isCGI = $request->isCGI(); if (!$this->isCGI) { $response->header('content-encoding', 'chunked'); $response->header('transfer-encoding', 'chunked'); } $response->sendHeaders(); $this->flow(); }
/** * Dispatches the route and returns the response. * * @access public * @return \mako\http\Response */ public function dispatch() { $returnValue = $this->beforeFilters(); if (!empty($returnValue)) { $this->response->body($returnValue); } else { $action = $this->route->getAction(); if ($action instanceof Closure) { $this->dispatchClosure($action); } else { $this->dispatchController($action); } if (!$this->skipAfterFilters) { $this->afterFilters(); } } return $this->response; }
/** * {@inheritdoc} */ public function send(Request $request, Response $response) { // Add headers that should always be included $response->type($this->options['content_type']); $response->header('accept-ranges', $request->isSafe() ? 'bytes' : 'none'); $response->header('content-disposition', $this->options['disposition'] . '; filename="' . $this->options['file_name'] . '"'); // Get the requested byte range $range = $request->header('range'); if ($range !== null) { $range = $this->calculateRange($range); } if ($range === false) { // Not an acceptable range so we'll just send an empty response // along with a "requested range not satisfiable" status $response->status(416); $response->sendHeaders(); } else { if ($range === null) { // No range was provided by the client so we'll just fake one for the sendFile method // and set the content-length header value to the full file size $range = ['start' => 0, 'end' => $this->fileSize - 1]; $response->header('content-length', $this->fileSize); } else { // Valid range so we'll need to tell the client which range we're sending // and set the content-length header value to the length of the byte range $response->status(206); $response->header('content-range', sprintf('bytes %s-%s/%s', $range['start'], $range['end'], $this->fileSize)); $response->header('content-length', $range['end'] - $range['start'] + 1); } // Send headers and the requested byte range $response->sendHeaders(); $this->sendFile($range['start'], $range['end']); // Execute callback if there is one if (!empty($this->options['callback'])) { $this->options['callback']($this->filePath); } } }