isRedirection() public method

Is the response a redirect?
public isRedirection ( ) : boolean
return boolean
Example #1
0
 public function after(Request $request, Response $response, Application $app)
 {
     if ($response->isRedirection()) {
         return;
     }
     // if ('application/json' === $request->headers->get('Accept')) {
     //     return $this->app()->json($this->data);
     // }
     //https://blog.yorunohikage.fr/
     //Pretty printing all JSON output in Silex PHP
     //if($response instanceof JsonResponse) {
     //    $response->setEncodingOptions(JSON_PRETTY_PRINT);
     //}
     if ($request->isXmlHttpRequest()) {
         $response_data = array('status' => 'OK', 'data' => $this->data);
         if (!is_null($this->error)) {
             $response_data['status'] = 'ERROR';
             $response_data['error'] = $this->error;
         }
         return $this->app->json($response_data);
     }
     if ($response->getContent() == '') {
         $this->initTwig();
         $response->setContent($this->twig()->render($this->template, $this->data));
     }
 }
Example #2
0
 public static function injectJavascript(Response $response)
 {
     if (app()->runningInConsole() || !self::isActive() || $response->isRedirection() || !config('2checkout.inject')) {
         return $response;
     }
     $content = $response->getContent();
     $response->setContent(str_replace("</body>", "<script src='https://www.2checkout.com/checkout/api/2co.min.js'></script>\n</body>", $content));
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function getParameters()
 {
     $code = null;
     $codeType = null;
     $cacheable = null;
     if (null !== $this->response) {
         $code = sprintf('%d', $this->response->getStatusCode());
         $cacheable = $this->response->isCacheable() ? 'cacheable' : 'not_cacheable';
         if ($this->response->isInformational()) {
             $codeType = 'informational';
         } elseif ($this->response->isSuccessful()) {
             $codeType = 'successful';
         } elseif ($this->response->isRedirection()) {
             $codeType = 'redirection';
         } elseif ($this->response->isClientError()) {
             $codeType = 'client_error';
         } elseif ($this->response->isServerError()) {
             $codeType = 'server_error';
         } else {
             $codeType = 'other';
         }
     }
     return array('response_code' => $code, 'response_code_type' => $codeType, 'response_cacheable' => $cacheable);
 }
Example #4
0
 /**
  * Modify the response and inject the debugbar (or data in headers)
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Symfony\Component\HttpFoundation\Response  $response
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function modifyResponse($request, $response)
 {
     $app = $this->app;
     if ($app->runningInConsole() or !$this->isEnabled() || $this->isDebugbarRequest()) {
         return $response;
     }
     if ($this->shouldCollect('config', false)) {
         try {
             $configCollector = new ConfigCollector();
             $configCollector->setData($app['config']->getItems());
             $this->addCollector($configCollector);
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add ConfigCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     /** @var \Illuminate\Session\SessionManager $sessionManager */
     $sessionManager = $app['session'];
     $httpDriver = new SymfonyHttpDriver($sessionManager, $response);
     $this->setHttpDriver($httpDriver);
     if ($this->shouldCollect('symfony_request', true) and !$this->hasCollector('request')) {
         try {
             $this->addCollector(new SymfonyRequestCollector($request, $response, $sessionManager));
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($response->isRedirection()) {
         try {
             $this->stackData();
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($request->isXmlHttpRequest() || $request->wantsJson() and $app['config']->get('laravel-debugbar::config.capture_ajax', true)) {
         try {
             $this->sendDataInHeaders(true);
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->format()) {
         //Do nothing
     } elseif ($app['config']->get('laravel-debugbar::config.inject', true)) {
         try {
             $this->injectDebugbar($response);
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     }
     // Stop further rendering (on subrequests etc)
     $this->disable();
     return $response;
 }
Example #5
0
 /**
  * deny.
  *
  * @method deny
  *
  * @param  \Symfony\Component\HttpFoundation\Response $response
  * @param  int                                        $statusCode
  *
  * @return bool
  */
 protected function deny(Response $response, $statusCode)
 {
     if ($response instanceof BinaryFileResponse) {
         return true;
     }
     if ($response instanceof StreamedResponse) {
         return true;
     }
     if ($response->isRedirection() === true) {
         return true;
     }
     if ($this->ajax === true) {
         return false;
     }
     $contentType = $response->headers->get('Content-Type');
     if (empty($contentType) === true && $statusCode >= 400) {
         return false;
     }
     if (count($this->accepts) === 0) {
         return false;
     }
     $contentType = strtolower($contentType);
     foreach ($this->accepts as $accept) {
         if (strpos($contentType, $accept) !== false) {
             return false;
         }
     }
     return true;
 }
Example #6
0
 /**
  * Determine if the given response should be cached.
  *
  * @param \Symfony\Component\HttpFoundation\Response $response
  *
  * @return bool
  */
 public function shouldCacheResponse(Response $response)
 {
     return $response->isSuccessful() || $response->isRedirection();
 }
 public function testIsRedirectRedirection()
 {
     foreach (array(301, 302, 303, 307) as $code) {
         $response = new Response('', $code);
         $this->assertTrue($response->isRedirection());
         $this->assertTrue($response->isRedirect());
     }
     $response = new Response('', 304);
     $this->assertTrue($response->isRedirection());
     $this->assertFalse($response->isRedirect());
     $response = new Response('', 200);
     $this->assertFalse($response->isRedirection());
     $this->assertFalse($response->isRedirect());
     $response = new Response('', 404);
     $this->assertFalse($response->isRedirection());
     $this->assertFalse($response->isRedirect());
     $response = new Response('', 301, array('Location' => '/good-uri'));
     $this->assertFalse($response->isRedirect('/bad-uri'));
     $this->assertTrue($response->isRedirect('/good-uri'));
 }
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     // Sub-requests and programmatic calls stay in the collected profile.
     if ($this->dumper || $this->requestStack && $this->requestStack->getMasterRequest() !== $request || $request->isXmlHttpRequest() || $request->headers->has('Origin')) {
         return;
     }
     // In all other conditions that remove the web debug toolbar, dumps are written on the output.
     if (!$this->requestStack || !$response->headers->has('X-Debug-Token') || $response->isRedirection() || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat() || false === strripos($response->getContent(), '</body>')) {
         if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
             $this->dumper = new HtmlDumper('php://output', $this->charset);
         } else {
             $this->dumper = new CliDumper('php://output', $this->charset);
         }
         foreach ($this->data as $dump) {
             $this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']);
         }
     }
 }
 /**
  * Modify the response and inject the debugbar (or data in headers)
  *
  * @param  \Symfony\Component\HttpFoundation\Request $request
  * @param  \Symfony\Component\HttpFoundation\Response $response
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function modifyResponse($request, $response)
 {
     $app = $this->app;
     if ($app->runningInConsole() || !$this->isEnabled() || $this->isDebugbarRequest()) {
         return $response;
     }
     if ($this->shouldCollect('config', false)) {
         try {
             $configCollector = new ConfigCollector();
             $configCollector->setData($app['config']->all());
             $this->addCollector($configCollector);
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add ConfigCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     /** @var \Illuminate\Session\SessionManager $sessionManager */
     $sessionManager = $app['session'];
     $httpDriver = new SymfonyHttpDriver($sessionManager, $response);
     $this->setHttpDriver($httpDriver);
     if ($this->shouldCollect('session')) {
         try {
             $this->addCollector(new SessionCollector($sessionManager));
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add SessionCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('symfony_request', true) && !$this->hasCollector('request')) {
         try {
             $this->addCollector(new SymfonyRequestCollector($request, $response, $sessionManager));
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($response->isRedirection()) {
         try {
             $this->stackData();
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($this->isJsonRequest($request) && $app['config']->get('debugbar.capture_ajax', true)) {
         try {
             $this->sendDataInHeaders(true);
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($response->headers->has('Content-Type') && strpos($response->headers->get('Content-Type'), 'html') === false || $request->getRequestFormat() !== 'html') {
         try {
             // Just collect + store data, don't inject it.
             $this->collect();
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($app['config']->get('debugbar.inject', true)) {
         try {
             $this->injectDebugbar($response);
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     }
     // Stop further rendering (on subrequests etc)
     $this->disable();
     return $response;
 }
 /**
  * Check if the response is a html page.
  *
  * @param Response $response
  * @return bool
  */
 private function isHtmlResponse(Response $response)
 {
     $headers = $response->headers;
     // assumes responses without Content-Type header are html
     return !$response->isRedirection() && (!$headers->has('Content-Type') || strpos($headers->get('Content-Type'), 'html') !== false);
 }
 public function assertRedirectedResponse(Response $response)
 {
     $this->assertTrue($response->isRedirection());
 }