From 978656874935543a88bea806067e29a8f9d3d582 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 30 Dec 2015 15:26:11 +1030 Subject: [PATCH] Extract method --- framework/core/src/Http/Middleware/StartSession.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Http/Middleware/StartSession.php b/framework/core/src/Http/Middleware/StartSession.php index 134616cf4..c28d13c20 100644 --- a/framework/core/src/Http/Middleware/StartSession.php +++ b/framework/core/src/Http/Middleware/StartSession.php @@ -33,9 +33,7 @@ class StartSession implements MiddlewareInterface $response = $out ? $out($request, $response) : $response; - if ($session->has('csrf_token')) { - $response = $response->withHeader('X-CSRF-Token', $session->get('csrf_token')); - } + $response = $this->withCsrfTokenHeader($response, $session); return $this->withSessionCookie($response, $session); } @@ -54,6 +52,15 @@ class StartSession implements MiddlewareInterface return $session; } + private function withCsrfTokenHeader(Response $response, SessionInterface $session) + { + if ($session->has('csrf_token')) { + $response = $response->withHeader('X-CSRF-Token', $session->get('csrf_token')); + } + + return $response; + } + private function withSessionCookie(Response $response, SessionInterface $session) { return FigResponseCookies::set(