From 9fc682a106f13901b60a665619fc61d9dae49fb0 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Wed, 16 Jun 2004 22:51:04 +0000 Subject: HTTP now has only one function. --- src/http.lua | 19 ++++++++----------- src/url.lua | 3 ++- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/http.lua b/src/http.lua index e0c4c27..b341ebb 100644 --- a/src/http.lua +++ b/src/http.lua @@ -122,7 +122,7 @@ local function uri(reqt) local u = reqt if not reqt.proxy and not PROXY then u = { - path = reqt.path, + path = socket.try(reqt.path, "invalid path 'nil'"), params = reqt.params, query = reqt.query, fragment = reqt.fragment @@ -152,18 +152,15 @@ local default = { local function adjustrequest(reqt) -- parse url if provided - if reqt.url then - local parsed = url.parse(reqt.url, default) - -- explicit components override url - for i,v in parsed do reqt[i] = reqt[i] or v end - end - socket.try(reqt.host, "invalid host '" .. tostring(reqt.host) .. "'") - socket.try(reqt.path, "invalid path '" .. tostring(reqt.path) .. "'") + local nreqt = reqt.url and url.parse(reqt.url, default) or {} + -- explicit components override url + for i,v in reqt do nreqt[i] = reqt[i] end + socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'") -- compute uri if user hasn't overriden - reqt.uri = reqt.uri or uri(reqt) + nreqt.uri = nreqt.uri or uri(nreqt) -- adjust headers in request - reqt.headers = adjustheaders(reqt.headers, reqt.host) - return reqt + nreqt.headers = adjustheaders(nreqt.headers, nreqt.host) + return nreqt end local function shouldredirect(reqt, code) diff --git a/src/url.lua b/src/url.lua index ec26e62..c708e19 100644 --- a/src/url.lua +++ b/src/url.lua @@ -115,7 +115,8 @@ end ----------------------------------------------------------------------------- function parse(url, default) -- initialize default parameters - local parsed = default or {} + local parsed = {} + for i,v in (default or parsed) do parsed[i] = v end -- empty url is parsed to nil if not url or url == "" then return nil, "invalid url" end -- remove whitespace -- cgit v1.2.3-55-g6feb