Software /
code /
prosody
Diff
net/http/parser.lua @ 4866:d54999db3aa1
net.http.parser: Do full URL decoding and parsing (e.g. adds request.url.query when present)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 12 May 2012 03:09:52 +0100 |
parent | 4716:6eeb142a8073 |
child | 4879:45bb378a4a98 |
line wrap: on
line diff
--- a/net/http/parser.lua Sat May 12 02:50:38 2012 +0100 +++ b/net/http/parser.lua Sat May 12 03:09:52 2012 +0100 @@ -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 @@ 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;