Skip to content

Commit

Permalink
merged branch lsmith77/force_content_type (PR #8050)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.2 branch.

Discussion
----------

[WebProfilerBundle] force the Content-Type to html in the web profiler controllers

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | [![Build Status](https://travis-ci.org/lsmith77/symfony.png?branch=force_content_type)](https://travis-ci.org/lsmith77/symfony)
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This just forces the Content-Type to match what will be returned, otherwise if the request format happens to be something else than HTML (which can be the case when building an app that only does JSON/XML with FOSRestBundle) it can happen that the Response class automatically sets a different Content-Type.

The approach taken here matches https://github.com/nelmio/NelmioApiDocBundle/blob/master/Controller/ApiDocController.php#L24

Commits
-------

6d2135b force the Content-Type to html in the web profiler controllers
  • Loading branch information
fabpot committed Jun 13, 2013
2 parents 9a76c4f + 6d2135b commit d0983f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Expand Up @@ -50,7 +50,7 @@ public function showAction($token)
if (!$this->twig->getLoader()->exists($template)) {
$handler = new ExceptionHandler();

return new Response($handler->getContent($exception));
return new Response($handler->getContent($exception), 200, array('Content-Type' => 'text/html'));
}

$code = $exception->getStatusCode();
Expand All @@ -64,7 +64,7 @@ public function showAction($token)
'logger' => null,
'currentContent' => '',
)
));
), 200, array('Content-Type' => 'text/html'));
}

/**
Expand All @@ -87,7 +87,7 @@ public function cssAction($token)
return new Response($handler->getStylesheet($exception));
}

return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'));
return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, 'text/css');
}

protected function getTemplate()
Expand Down
Expand Up @@ -61,7 +61,7 @@ public function homeAction()
{
$this->profiler->disable();

return new RedirectResponse($this->generator->generate('_profiler_search_results', array('token' => 'empty', 'limit' => 10)));
return new RedirectResponse($this->generator->generate('_profiler_search_results', array('token' => 'empty', 'limit' => 10)), 302, array('Content-Type' => 'text/html'));
}

/**
Expand All @@ -82,7 +82,7 @@ public function panelAction(Request $request, $token)
$page = $request->query->get('page', 'home');

if (!$profile = $this->profiler->loadProfile($token)) {
return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array('about' => 'no_token', 'token' => $token)));
return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array('about' => 'no_token', 'token' => $token)), 200, array('Content-Type' => 'text/html'));
}

if (!$profile->hasCollector($panel)) {
Expand All @@ -98,7 +98,7 @@ public function panelAction(Request $request, $token)
'request' => $request,
'templates' => $this->getTemplateManager()->getTemplates($profile),
'is_ajax' => $request->isXmlHttpRequest(),
)));
)), 200, array('Content-Type' => 'text/html'));
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ public function purgeAction()
$this->profiler->disable();
$this->profiler->purge();

return new RedirectResponse($this->generator->generate('_profiler_info', array('about' => 'purge')));
return new RedirectResponse($this->generator->generate('_profiler_info', array('about' => 'purge')), 302, array('Content-Type' => 'text/html'));
}

/**
Expand All @@ -151,14 +151,14 @@ public function importAction(Request $request)
$file = $request->files->get('file');

if (empty($file) || !$file->isValid()) {
return new RedirectResponse($this->generator->generate('_profiler_info', array('about' => 'upload_error')));
return new RedirectResponse($this->generator->generate('_profiler_info', array('about' => 'upload_error')), 302, array('Content-Type' => 'text/html'));
}

if (!$profile = $this->profiler->import(file_get_contents($file->getPathname()))) {
return new RedirectResponse($this->generator->generate('_profiler_info', array('about' => 'already_exists')));
return new RedirectResponse($this->generator->generate('_profiler_info', array('about' => 'already_exists')), 302, array('Content-Type' => 'text/html'));
}

return new RedirectResponse($this->generator->generate('_profiler', array('token' => $profile->getToken())));
return new RedirectResponse($this->generator->generate('_profiler', array('token' => $profile->getToken())), 302, array('Content-Type' => 'text/html'));
}

/**
Expand All @@ -174,7 +174,7 @@ public function infoAction($about)

return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array(
'about' => $about
)));
)), 200, array('Content-Type' => 'text/html'));
}

/**
Expand All @@ -195,13 +195,13 @@ public function toolbarAction(Request $request, $token)
}

if (null === $token) {
return new Response();
return new Response('', 200, array('Content-Type' => 'text/html'));
}

$this->profiler->disable();

if (!$profile = $this->profiler->loadProfile($token)) {
return new Response();
return new Response('', 200, array('Content-Type' => 'text/html'));
}

// the toolbar position (top, bottom, normal, or null -- use the configuration)
Expand All @@ -222,7 +222,7 @@ public function toolbarAction(Request $request, $token)
'templates' => $this->getTemplateManager()->getTemplates($profile),
'profiler_url' => $url,
'token' => $token,
)));
)), 200, array('Content-Type' => 'text/html'));
}

/**
Expand Down Expand Up @@ -262,7 +262,7 @@ public function searchBarAction(Request $request)
'start' => $start,
'end' => $end,
'limit' => $limit,
)));
)), 200, array('Content-Type' => 'text/html'));
}

/**
Expand Down Expand Up @@ -297,7 +297,7 @@ public function searchResultsAction(Request $request, $token)
'end' => $end,
'limit' => $limit,
'panel' => null,
)));
)), 200, array('Content-Type' => 'text/html'));
}

/**
Expand Down Expand Up @@ -330,7 +330,7 @@ public function searchAction(Request $request)
}

if (!empty($token)) {
return new RedirectResponse($this->generator->generate('_profiler', array('token' => $token)));
return new RedirectResponse($this->generator->generate('_profiler', array('token' => $token)), 302, array('Content-Type' => 'text/html'));
}

$tokens = $this->profiler->find($ip, $url, $limit, $method, $start, $end);
Expand All @@ -343,7 +343,7 @@ public function searchAction(Request $request)
'start' => $start,
'end' => $end,
'limit' => $limit,
)));
)), 302, array('Content-Type' => 'text/html'));
}

/**
Expand All @@ -359,7 +359,7 @@ public function phpinfoAction()
phpinfo();
$phpinfo = ob_get_clean();

return new Response($phpinfo);
return new Response($phpinfo, 200, array('Content-Type' => 'text/html'));
}

/**
Expand Down
Expand Up @@ -53,7 +53,7 @@ public function panelAction($token)
$this->profiler->disable();

if (null === $this->matcher || null === $this->routes) {
return new Response('The Router is not enabled.');
return new Response('The Router is not enabled.', 200, array('Content-Type' => 'text/html'));
}

$profile = $this->profiler->loadProfile($token);
Expand All @@ -68,6 +68,6 @@ public function panelAction($token)
'request' => $request,
'router' => $profile->getCollector('router'),
'traces' => $matcher->getTraces($request->getPathInfo()),
)));
)), 200, array('Content-Type' => 'text/html'));
}
}

0 comments on commit d0983f0

Please sign in to comment.