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