From bd0e2a04b009935a0908dd0f15a64de9bfd0029c Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Fri, 20 May 2022 15:40:44 -0600 Subject: [PATCH] Add getparams and cookie middleware to new Handlers framework --- src/Handlers.jl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Handlers.jl b/src/Handlers.jl index 6cf029a5d..e18654ce2 100644 --- a/src/Handlers.jl +++ b/src/Handlers.jl @@ -1,9 +1,9 @@ module Handlers -export serve, Router, register! +export serve, Router, register!, getparams, getcookies using URIs -using ..Messages, ..Streams, ..IOExtras, ..Servers, ..Sockets +using ..Messages, ..Streams, ..IOExtras, ..Servers, ..Sockets, ..Cookies """ streamhandler(request_handler) -> stream handler @@ -291,4 +291,17 @@ function (r::Router)(req) end end -end # module +getparams(req) = get(req.context, :params, nothing) + +function cookie_middleware(handler) + function (req) + if !haskey(req.context, :cookies) + req.context[:cookies] = Cookies.cookies(req) + end + return handler(req) + end +end + +getcookies(req) = get(() => Cookie[], req.context, :cookies) + +end # module \ No newline at end of file