Skip to content

Commit

Permalink
Refactoring Middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 24, 2015
1 parent 029fada commit 9872026
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/Bases/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,20 @@ protected function getLocalizedRedirect($locale)

if ( ! is_string($localizedUrl)) return null;

return new RedirectResponse($localizedUrl, 302, [
return $this->makeRedirectResponse($localizedUrl);
}

/**
* Make a redirect response.
*
* @param string $url
* @param int $code
*
* @return RedirectResponse
*/
protected function makeRedirectResponse($url, $code = 302)
{
return new RedirectResponse($url, $code, [
'Vary' => 'Accept-Language'
]);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Middleware/LocalizationRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Arcanedev\Localization\Bases\Middleware;
use Closure;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

/**
Expand Down Expand Up @@ -37,9 +36,7 @@ public function handle(Request $request, Closure $next)
// Save any flashed data for redirect
session()->reflash();

return new RedirectResponse($redirectUrl, 301, [
'Vary' => 'Accept-Language'
]);
return $this->makeRedirectResponse($redirectUrl, 301);
}

return $next($request);
Expand Down

0 comments on commit 9872026

Please sign in to comment.