Mercurial > prosody-hg
comparison plugins/mod_http.lua @ 4736:3514338c59c3
net.http.server, mod_http: Support http_default_host config option to specify where to direct requests for unknown HTTP vhosts
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 27 Apr 2012 23:11:23 +0100 |
| parents | a8c234332258 |
| children | b2ed4e1bcb6e |
comparison
equal
deleted
inserted
replaced
| 4735:474166c08319 | 4736:3514338c59c3 |
|---|---|
| 7 -- | 7 -- |
| 8 | 8 |
| 9 module:set_global(); | 9 module:set_global(); |
| 10 | 10 |
| 11 local server = require "net.http.server"; | 11 local server = require "net.http.server"; |
| 12 | |
| 13 server.set_default_host(module:get_option_string("http_default_host")); | |
| 12 | 14 |
| 13 local function normalize_path(path) | 15 local function normalize_path(path) |
| 14 if path:sub(1,1) ~= "/" then path = "/"..path; end | 16 if path:sub(1,1) ~= "/" then path = "/"..path; end |
| 15 if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end | 17 if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end |
| 16 return path; | 18 return path; |
| 81 module:unhook_object_event(server, event, handler); | 83 module:unhook_object_event(server, event, handler); |
| 82 end | 84 end |
| 83 end | 85 end |
| 84 | 86 |
| 85 module:handle_items("http-provider", http_app_added, http_app_removed); | 87 module:handle_items("http-provider", http_app_added, http_app_removed); |
| 88 | |
| 89 server.add_host(host); | |
| 90 function module.unload() | |
| 91 server.remove_host(host); | |
| 92 end | |
| 86 end | 93 end |
| 87 | 94 |
| 88 module:add_item("net-provider", { | 95 module:add_item("net-provider", { |
| 89 name = "http"; | 96 name = "http"; |
| 90 listener = server.listener; | 97 listener = server.listener; |
