Mercurial > prosody-hg
comparison 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 |
| parents | 6eeb142a8073 |
| children | 45bb378a4a98 |
comparison
equal
deleted
inserted
replaced
| 4865:9171dc2357e0 | 4866:d54999db3aa1 |
|---|---|
| 1 | 1 |
| 2 local tonumber = tonumber; | 2 local tonumber = tonumber; |
| 3 local assert = assert; | 3 local assert = assert; |
| 4 local url_parse = require "socket.url".parse; | |
| 5 local urldecode = require "net.http".urldecode; | |
| 4 | 6 |
| 5 local function preprocess_path(path) | 7 local function preprocess_path(path) |
| 8 path = urldecode(path); | |
| 6 if path:sub(1,1) ~= "/" then | 9 if path:sub(1,1) ~= "/" then |
| 7 path = "/"..path; | 10 path = "/"..path; |
| 8 end | 11 end |
| 9 local level = 0; | 12 local level = 0; |
| 10 for component in path:gmatch("([^/]+)/") do | 13 for component in path:gmatch("([^/]+)/") do |
| 86 -- COMPAT the properties below are deprecated | 89 -- COMPAT the properties below are deprecated |
| 87 responseversion = httpversion; | 90 responseversion = httpversion; |
| 88 responseheaders = headers; | 91 responseheaders = headers; |
| 89 }; | 92 }; |
| 90 else | 93 else |
| 91 -- path normalization | 94 local parsed_url = url_parse(path); |
| 92 if path:match("^https?://") then | 95 path = preprocess_path(parsed_url.path); |
| 93 headers.host, path = path:match("^https?://([^/]*)(.*)"); | 96 headers.host = parsed_url.host; |
| 94 end | |
| 95 path = preprocess_path(path); | |
| 96 | 97 |
| 97 len = len or 0; | 98 len = len or 0; |
| 98 packet = { | 99 packet = { |
| 99 method = method; | 100 method = method; |
| 101 url = parsed_url; | |
| 100 path = path; | 102 path = path; |
| 101 httpversion = httpversion; | 103 httpversion = httpversion; |
| 102 headers = headers; | 104 headers = headers; |
| 103 body = nil; | 105 body = nil; |
| 104 }; | 106 }; |
