Software /
code /
prosody
Comparison
net/http/parser.lua @ 4716:6eeb142a8073
mod_http_files, net.http.parser: Move path normalization to net.http.parser so that all modules can benefit
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 26 Apr 2012 16:48:16 +0100 |
parent | 4712:4fc99f1b7570 |
child | 4866:d54999db3aa1 |
comparison
equal
deleted
inserted
replaced
4715:4d6ebe54671e | 4716:6eeb142a8073 |
---|---|
1 | 1 |
2 local tonumber = tonumber; | 2 local tonumber = tonumber; |
3 local assert = assert; | 3 local assert = assert; |
4 | |
5 local function preprocess_path(path) | |
6 if path:sub(1,1) ~= "/" then | |
7 path = "/"..path; | |
8 end | |
9 local level = 0; | |
10 for component in path:gmatch("([^/]+)/") do | |
11 if component == ".." then | |
12 level = level - 1; | |
13 elseif component ~= "." then | |
14 level = level + 1; | |
15 end | |
16 if level < 0 then | |
17 return nil; | |
18 end | |
19 end | |
20 return path; | |
21 end | |
4 | 22 |
5 local httpstream = {}; | 23 local httpstream = {}; |
6 | 24 |
7 function httpstream.new(success_cb, error_cb, parser_type, options_cb) | 25 function httpstream.new(success_cb, error_cb, parser_type, options_cb) |
8 local client = true; | 26 local client = true; |
72 else | 90 else |
73 -- path normalization | 91 -- path normalization |
74 if path:match("^https?://") then | 92 if path:match("^https?://") then |
75 headers.host, path = path:match("^https?://([^/]*)(.*)"); | 93 headers.host, path = path:match("^https?://([^/]*)(.*)"); |
76 end | 94 end |
77 path = path:gsub("^//+", "/"); -- TODO parse url more | 95 path = preprocess_path(path); |
78 | 96 |
79 len = len or 0; | 97 len = len or 0; |
80 packet = { | 98 packet = { |
81 method = method; | 99 method = method; |
82 path = path; | 100 path = path; |