aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/http.lua2
-rw-r--r--net/http/parser.lua12
2 files changed, 8 insertions, 6 deletions
diff --git a/net/http.lua b/net/http.lua
index 59f2c080..f2061e00 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -68,7 +68,7 @@ function listener.ondisconnect(conn, err)
requests[conn] = nil;
end
-function urlencode(s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end
+function urlencode(s) return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return format("%%%02x", c:byte()); end)); end
function urldecode(s) return s and (s:gsub("%%(%x%x)", function (c) return char(tonumber(c,16)); end)); end
local function _formencodepart(s)
diff --git a/net/http/parser.lua b/net/http/parser.lua
index 3d9d1a87..d3f0dc03 100644
--- a/net/http/parser.lua
+++ b/net/http/parser.lua
@@ -1,8 +1,11 @@
local tonumber = tonumber;
local assert = assert;
+local url_parse = require "socket.url".parse;
+local urldecode = require "net.http".urldecode;
local function preprocess_path(path)
+ path = urldecode(path);
if path:sub(1,1) ~= "/" then
path = "/"..path;
end
@@ -88,15 +91,14 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
responseheaders = headers;
};
else
- -- path normalization
- if path:match("^https?://") then
- headers.host, path = path:match("^https?://([^/]*)(.*)");
- end
- path = preprocess_path(path);
+ local parsed_url = url_parse(path);
+ path = preprocess_path(parsed_url.path);
+ headers.host = parsed_url.host;
len = len or 0;
packet = {
method = method;
+ url = parsed_url;
path = path;
httpversion = httpversion;
headers = headers;