Skip to content

Commit

Permalink
Moved response conditions to middleware + Fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
dmongeau committed May 29, 2017
1 parent f06fe1b commit 5bb7085
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
15 changes: 3 additions & 12 deletions src/Folklore/Hypernova/Hypernova.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 12 additions & 1 deletion src/Folklore/Hypernova/HypernovaMiddleware.php
Expand Up @@ -3,6 +3,7 @@
namespace Folklore\Hypernova;

use Closure;
use Symfony\Component\HttpFoundation\Response as BaseResponse;

class HypernovaMiddleware
{
Expand All @@ -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;
}
}

0 comments on commit 5bb7085

Please sign in to comment.