Software / code / prosody
Comparison
plugins/mod_http.lua @ 9504:cfbea3064aa9
mod_http: Move normalize_path to util.http
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 14 Oct 2018 14:31:59 +0200 |
| parent | 9503:3456496d5218 |
| child | 9793:9993fd021d19 |
| child | 11381:8603011e51fe |
comparison
equal
deleted
inserted
replaced
| 9503:3456496d5218 | 9504:cfbea3064aa9 |
|---|---|
| 11 | 11 |
| 12 local portmanager = require "core.portmanager"; | 12 local portmanager = require "core.portmanager"; |
| 13 local moduleapi = require "core.moduleapi"; | 13 local moduleapi = require "core.moduleapi"; |
| 14 local url_parse = require "socket.url".parse; | 14 local url_parse = require "socket.url".parse; |
| 15 local url_build = require "socket.url".build; | 15 local url_build = require "socket.url".build; |
| 16 local normalize_path = require "util.http".normalize_path; | |
| 16 | 17 |
| 17 local server = require "net.http.server"; | 18 local server = require "net.http.server"; |
| 18 | 19 |
| 19 server.set_default_host(module:get_option_string("http_default_host")); | 20 server.set_default_host(module:get_option_string("http_default_host")); |
| 20 | 21 |
| 21 server.set_option("body_size_limit", module:get_option_number("http_max_content_size")); | 22 server.set_option("body_size_limit", module:get_option_number("http_max_content_size")); |
| 22 server.set_option("buffer_size_limit", module:get_option_number("http_max_buffer_size")); | 23 server.set_option("buffer_size_limit", module:get_option_number("http_max_buffer_size")); |
| 23 | |
| 24 local function normalize_path(path, is_dir) | |
| 25 if is_dir then | |
| 26 if path:sub(-1,-1) ~= "/" then path = path.."/"; end | |
| 27 else | |
| 28 if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end | |
| 29 end | |
| 30 if path:sub(1,1) ~= "/" then path = "/"..path; end | |
| 31 return path; | |
| 32 end | |
| 33 | 24 |
| 34 local function get_http_event(host, app_path, key) | 25 local function get_http_event(host, app_path, key) |
| 35 local method, path = key:match("^(%S+)%s+(.+)$"); | 26 local method, path = key:match("^(%S+)%s+(.+)$"); |
| 36 if not method then -- No path specified, default to "" (base path) | 27 if not method then -- No path specified, default to "" (base path) |
| 37 method, path = key, ""; | 28 method, path = key, ""; |