aboutsummaryrefslogtreecommitdiff
path: root/src/guff/handlers/session.cr
blob: bc7a5bc39214489bee2d0b7bd2145b1f39155727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require "json"
require "../handler"

class Guff::Handlers::SessionHandler < Guff::Handler
  def call(context : HTTP::Server::Context)
    if cookie = context.request.cookies["guff_session"]?
      # get session id
      sid = cookie.value
      puts "DEBUG: session_id = #{sid}"
      context.request.headers["x-guff-session-id"] = sid
    end

    call_next(context)

    if sid = context.request.headers["x-guff-session-id"]?
      # FIXME: need way to delete cookie
      cookie = HTTP::Cookie.new("guff_session", sid)
      context.response.headers["set-cookie"] = cookie.to_set_cookie_header
    end
  end
end