diff options
author | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2012-09-04 18:00:57 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2012-09-04 18:00:57 +0000 |
commit | 402201ca29667b6c2dd37b9b681901c8f1106527 (patch) | |
tree | 7e7c2153c2b9118de9e12a14f9699aa359e31562 | |
parent | 1bdf108eecc7e26540e16d2e5522d26ee1db7b42 (diff) | |
download | lem-402201ca29667b6c2dd37b9b681901c8f1106527.tar.gz lem-402201ca29667b6c2dd37b9b681901c8f1106527.tar.xz lem-402201ca29667b6c2dd37b9b681901c8f1106527.zip |
http: match requests on path excluding query component
Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz>
-rw-r--r-- | lem/hathaway.lua | 35 | ||||
-rw-r--r-- | lem/http/server.lua | 10 |
2 files changed, 28 insertions, 17 deletions
diff --git a/lem/hathaway.lua b/lem/hathaway.lua index 6d4e2da..b23934c 100644 --- a/lem/hathaway.lua +++ b/lem/hathaway.lua @@ -50,28 +50,28 @@ do local lookup = {} M.lookup = lookup - function M.GET(uri, handler) - local path = lookup[uri] - if path then - path['HEAD'] = handler - path['GET'] = handler + function M.GET(path, handler) + local entry = lookup[path] + if entry then + entry['HEAD'] = handler + entry['GET'] = handler else - path = { + entry = { ['HEAD'] = handler, ['GET'] = handler, } - lookup[uri] = path + lookup[path] = entry end end do local function static_setter(method) - return function(uri, handler) - local path = lookup[uri] - if path then - path[method] = handler + return function(path, handler) + local entry = lookup[path] + if entry then + entry[method] = handler else - lookup[uri] = { [method] = handler } + lookup[path] = { [method] = handler } end end end @@ -137,10 +137,11 @@ do end local function handler(req, res) - local method, uri, version = req.method, req.uri, req.version - local path = lookup[uri] - if path then - local handler = path[method] + local method, path, version = req.method, req.path, req.version + + local entry = lookup[path] + if entry then + local handler = entry[method] if handler then handler(req, res) else @@ -155,7 +156,7 @@ do M.not_found(req, res) break end - until check_match(entry, req, res, uri:match(entry[1])) + until check_match(entry, req, res, path:match(entry[1])) end end diff --git a/lem/http/server.lua b/lem/http/server.lua index 2e15cd0..155d681 100644 --- a/lem/http/server.lua +++ b/lem/http/server.lua @@ -121,6 +121,16 @@ do local req, err = istream:read('HTTPRequest') if not req then M.debug(err) break end local method, uri, version = req.method, req.uri, req.version + + do + local pos = req.uri:find('?', 1, true) + if pos ~= nil then + req.path = req.uri:sub(1, pos-1) + else + req.path = req.uri + end + end + M.debug(format("%s %s HTTP/%s", method, uri, version)) req.ostream = ostream |