Пример #1
0
 /**
  * Forwards dispatching to another router.
  *
  * @param Route $route
  *
  * @return Response|mixed
  */
 protected function forward_to_route(Route $route)
 {
     $route->pattern->match($this->request->uri, $captured);
     $request = $this->request->with(['path_params' => $captured]);
     $request->context->route = $route;
     $controller = $route->controller;
     if (!is_callable($controller)) {
         $controller = new $controller();
     }
     return $controller($request);
 }
Пример #2
0
 /**
  * Trying to rescue a NotFound HEAD request using GET instead.
  *
  * @param Request $request
  *
  * @return Response
  */
 private function handle_head(Request $request)
 {
     $response = $this->handle($request->with([Request::OPTION_IS_GET => true]));
     if ($response->content_length === null && !$response->body instanceof \Closure) {
         try {
             $response->content_length = strlen((string) $response->body);
         } catch (\Exception $e) {
             #
             # It's not that bad if we can't obtain the length of the body.
             #
         }
     }
     return $response;
 }