Software /
code /
prosody
Diff
util/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 | 5471:34bfd26525f5 |
child | 9759:1af5106a2c34 |
line wrap: on
line diff
--- a/util/http.lua Sun Oct 14 14:19:21 2018 +0200 +++ b/util/http.lua Sun Oct 14 14:31:59 2018 +0200 @@ -57,8 +57,19 @@ return field:find(","..token:lower()..",", 1, true) ~= nil; end +local function normalize_path(path, is_dir) + if is_dir then + if path:sub(-1,-1) ~= "/" then path = path.."/"; end + else + if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end + end + if path:sub(1,1) ~= "/" then path = "/"..path; end + return path; +end + return { urlencode = urlencode, urldecode = urldecode; formencode = formencode, formdecode = formdecode; contains_token = contains_token; + normalize_path = normalize_path; };