66a86a7ff75dfd3764d02ba855acaa0aacda2d66
[project/luci.git] / libs / lucid-http / luasrc / lucid / http / Redirector.lua
1 --[[
2 LuCId HTTP-Slave
3 (c) 2009 Steven Barth <steven@midlink.org>
4
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
8
9         http://www.apache.org/licenses/LICENSE-2.0
10
11 $Id$
12 ]]--
13
14 local ipairs = ipairs
15 local catchall = require "luci.lucid.http.handler.catchall"
16 local srv = require "luci.lucid.http.server"
17
18 module "luci.lucid.http.Redirector"
19
20 --- Prepare a redirector publisher and assign it to a given Virtual Host.
21 -- @param server HTTP daemon object
22 -- @param config publisher configuration
23 function factory(server, config)
24         config.domain = config.domain or ""
25         local vhost = server:get_vhosts()[config.domain] 
26         if not vhost then
27                 vhost = srv.VHost()
28                 server:set_vhost(config.domain, vhost)
29         end
30
31         local handler = catchall.Redirect(config.name, config.physical)
32         vhost:set_handler(config.virtual or "", handler)
33 end