From d68d3a3357c46933b604c03a8f8d6a60fa952106 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 21 May 2016 13:44:12 -0400 Subject: DRY session cookie name --- src/guff.cr | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/guff.cr b/src/guff.cr index f25e1c3..503fded 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -303,6 +303,10 @@ module Guff class Session < Hash(String, String) getter :session_id + # session cookie name + # FIXME: does this belong here + COOKIE = "guff_session" + def initialize(@context : Context) super() @session_id = nil @@ -474,9 +478,9 @@ module Guff # clear session @context.session.clear - if context.request.cookies.has_key?("guff_sid") + if cookie = context.request.cookies[Guff::Session::COOKIE]? # load session - @context.session.load(context.request.cookies["guff_sid"].value) + @context.session.load(cookie.value) end call_next(context) @@ -606,7 +610,7 @@ module Guff # add cookie context.response.cookies << HTTP::Cookie.new( - name: "guff_sid", + name: Guff::Session::COOKIE, value: session_id as String, http_only: true, @@ -698,7 +702,7 @@ module Guff # clear cookie context.response.cookies << HTTP::Cookie.new( - name: "guff_sid", + name: Guff::Session::COOKIE, value: "", expires: Time.epoch(0), http_only: true, -- cgit v1.2.3