Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0983f0

Browse files
committed
merged branch lsmith77/force_content_type (PR #8050)
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
2 parents 9a76c4f + 6d2135b commit d0983f0

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function showAction($token)
5050
if (!$this->twig->getLoader()->exists($template)) {
5151
$handler = new ExceptionHandler();
5252

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

5656
$code = $exception->getStatusCode();
@@ -64,7 +64,7 @@ public function showAction($token)
6464
'logger' => null,
6565
'currentContent' => '',
6666
)
67-
));
67+
), 200, array('Content-Type' => 'text/html'));
6868
}
6969

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

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

9393
protected function getTemplate()

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function homeAction()
6161
{
6262
$this->profiler->disable();
6363

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

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

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

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

104104
/**
@@ -134,7 +134,7 @@ public function purgeAction()
134134
$this->profiler->disable();
135135
$this->profiler->purge();
136136

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

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

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

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

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

164164
/**
@@ -174,7 +174,7 @@ public function infoAction($about)
174174

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

180180
/**
@@ -195,13 +195,13 @@ public function toolbarAction(Request $request, $token)
195195
}
196196

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

201201
$this->profiler->disable();
202202

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

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

228228
/**
@@ -262,7 +262,7 @@ public function searchBarAction(Request $request)
262262
'start' => $start,
263263
'end' => $end,
264264
'limit' => $limit,
265-
)));
265+
)), 200, array('Content-Type' => 'text/html'));
266266
}
267267

268268
/**
@@ -297,7 +297,7 @@ public function searchResultsAction(Request $request, $token)
297297
'end' => $end,
298298
'limit' => $limit,
299299
'panel' => null,
300-
)));
300+
)), 200, array('Content-Type' => 'text/html'));
301301
}
302302

303303
/**
@@ -330,7 +330,7 @@ public function searchAction(Request $request)
330330
}
331331

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

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

349349
/**
@@ -359,7 +359,7 @@ public function phpinfoAction()
359359
phpinfo();
360360
$phpinfo = ob_get_clean();
361361

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

365365
/**

src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function panelAction($token)
5353
$this->profiler->disable();
5454

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

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

0 commit comments

Comments
 (0)