From 5bb7085b2be6bbc85d455d301d04fbbbc9c1cd00 Mon Sep 17 00:00:00 2001 From: David Mongeau-Petitpas Date: Mon, 29 May 2017 13:56:12 -0400 Subject: [PATCH] Moved response conditions to middleware + Fixes #2 --- src/Folklore/Hypernova/Hypernova.php | 15 +++------------ src/Folklore/Hypernova/HypernovaMiddleware.php | 13 ++++++++++++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Folklore/Hypernova/Hypernova.php b/src/Folklore/Hypernova/Hypernova.php index 6de84fa..e23314e 100644 --- a/src/Folklore/Hypernova/Hypernova.php +++ b/src/Folklore/Hypernova/Hypernova.php @@ -5,7 +5,6 @@ use Illuminate\Container\Container; use Ramsey\Uuid\Uuid; use Folklore\Hypernova\Contracts\Renderer as RendererContract; -use Symfony\Component\HttpFoundation\Response as BaseResponse; use Illuminate\Contracts\Support\Renderable; class Hypernova @@ -117,17 +116,9 @@ public function renderComponent($name, $data = []) public function modifyResponse($response) { - if ($response instanceof BaseResponse && - !$response->isRedirection() && - ( - !$response->headers->has('Content-Type') || - $response->headers->has('Content-Type') === 'text/html' - ) - ) { - $content = $response->getContent(); - $content = $this->replaceContents($content); - $response->setContent($content); - } + $content = $response->getContent(); + $content = $this->replaceContents($content); + $response->setContent($content); return $response; } diff --git a/src/Folklore/Hypernova/HypernovaMiddleware.php b/src/Folklore/Hypernova/HypernovaMiddleware.php index 9a02d93..22eb595 100644 --- a/src/Folklore/Hypernova/HypernovaMiddleware.php +++ b/src/Folklore/Hypernova/HypernovaMiddleware.php @@ -3,6 +3,7 @@ namespace Folklore\Hypernova; use Closure; +use Symfony\Component\HttpFoundation\Response as BaseResponse; class HypernovaMiddleware { @@ -18,6 +19,16 @@ public function handle($request, Closure $next, $guard = null) { $response = $next($request); - return app('hypernova')->modifyResponse($response); + if ($response instanceof BaseResponse && + !$response->isRedirection() && + ( + !$response->headers->has('Content-Type') || + strpos($response->headers->has('Content-Type'), 'text/html') !== false + ) + ) { + return app('hypernova')->modifyResponse($response); + } + + return $response; } }