3 (c) 2009 Steven Barth <steven@midlink.org>
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
14 local srv = require "luci.lucid.http.server"
15 local proto = require "luci.http.protocol"
17 module "luci.lucid.http.handler.catchall"
19 Redirect = util.class(srv.Handler)
21 function Redirect.__init__(self, name, target)
22 srv.Handler.__init__(self, name)
26 function Redirect.handle_GET(self, request)
27 local target = self.target
28 local protocol = request.env.HTTPS and "https://" or "http://"
29 local server = request.env.SERVER_ADDR
30 if server:find(":") then
31 server = "[" .. server .. "]"
34 if self.target:sub(1,1) == ":" then
35 target = protocol .. server .. target
38 local s, e = target:find("%TARGET%", 1, true)
40 local req = protocol .. (request.env.HTTP_HOST or server)
41 .. request.env.REQUEST_URI
42 target = target:sub(1, s-1) .. req .. target:sub(e+1)
45 return 302, { Location = target }
48 Redirect.handle_POST = Redirect.handle_GET
50 function Redirect.handle_HEAD(self, request)
51 local stat, head = self:handle_GET(request)