Software /
code /
prosody
Comparison
plugins/mod_http.lua @ 9502:09e7b0048ebe
mod_http: Make sure path from http_external_url always ends with a slash (fixes #1183)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 14 Oct 2018 14:01:57 +0200 |
parent | 7867:194f540e13e2 |
child | 9503:3456496d5218 |
comparison
equal
deleted
inserted
replaced
9280:37b796cc366a | 9502:09e7b0048ebe |
---|---|
19 server.set_default_host(module:get_option_string("http_default_host")); | 19 server.set_default_host(module:get_option_string("http_default_host")); |
20 | 20 |
21 server.set_option("body_size_limit", module:get_option_number("http_max_content_size")); | 21 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")); | 22 server.set_option("buffer_size_limit", module:get_option_number("http_max_buffer_size")); |
23 | 23 |
24 local function normalize_path(path) | 24 local function normalize_path(path, is_dir) |
25 if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end | 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 | |
26 if path:sub(1,1) ~= "/" then path = "/"..path; end | 30 if path:sub(1,1) ~= "/" then path = "/"..path; end |
27 return path; | 31 return path; |
28 end | 32 end |
29 | 33 |
30 local function get_http_event(host, app_path, key) | 34 local function get_http_event(host, app_path, key) |
68 for port, services in pairs(ports) do | 72 for port, services in pairs(ports) do |
69 local url = { | 73 local url = { |
70 scheme = (external_url.scheme or services[1].service.name); | 74 scheme = (external_url.scheme or services[1].service.name); |
71 host = (external_url.host or module:get_option_string("http_host", module.host)); | 75 host = (external_url.host or module:get_option_string("http_host", module.host)); |
72 port = tonumber(external_url.port) or port or 80; | 76 port = tonumber(external_url.port) or port or 80; |
73 path = normalize_path(external_url.path or "/").. | 77 path = normalize_path(external_url.path or "/", true).. |
74 (get_base_path(module, app_name, default_path or "/"..app_name):sub(2)); | 78 (get_base_path(module, app_name, default_path or "/"..app_name):sub(2)); |
75 } | 79 } |
76 if ports_by_scheme[url.scheme] == url.port then url.port = nil end | 80 if ports_by_scheme[url.scheme] == url.port then url.port = nil end |
77 return url_build(url); | 81 return url_build(url); |
78 end | 82 end |