Skip to content

Commit

Permalink
Add getparams and cookie middleware to new Handlers framework
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed May 20, 2022
1 parent 7cab2ab commit bd0e2a0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Handlers.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit bd0e2a0

Please sign in to comment.