Skip to content

Commit

Permalink
More testing of middleware; start work on formal middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk committed Mar 6, 2013
1 parent 09b15ac commit f537b0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/Middleware.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Middleware
# Middleware are wrapper functions around the main app function. They
# have 3 arguments (app, req, res) instead of the regular two (req, res)
# and return a function that accepts the regular two like a normal app.
# However that function exists within the 3-argument closure and calls the
# closured app function after doing its modifications to the req/res.
#
# The suggested means of action for middleware is to modifiy the req.env
# dict to send/receive data from the app.

include("Middleware/CookieSession.jl")
end
Empty file added src/Middleware/CookieSession.jl
Empty file.
15 changes: 12 additions & 3 deletions test/middleware.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ function test_app(req, res)
end
end

function test_middleware(app)
function test_middleware1(app)
return function(req, res)
ret = HTTP.Util.wrap_app(app, req, res)
res.body *= " (Middlewared!)"
res.body *= " (Middlewar1'ed!)"
return ret
end
end

BasicServer.bind(8000, test_middleware(test_app), true)
function test_middleware2(app)
return function(req, res)
ret = HTTP.Util.wrap_app(app, req, res)
res.body *= " (Middlewar2'ed!)"
return ret
end
end


BasicServer.bind(8000, test_middleware1(test_middleware2(test_app)), true)

0 comments on commit f537b0c

Please sign in to comment.