diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-16 22:51:04 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-16 22:51:04 +0000 |
commit | 9fc682a106f13901b60a665619fc61d9dae49fb0 (patch) | |
tree | 6efdd73fa4f2abce56b6fb710f7516d0a5c6c758 /src | |
parent | 574708380f19b15bd19419bfd64ccbe422f2d924 (diff) | |
download | luasocket-9fc682a106f13901b60a665619fc61d9dae49fb0.tar.gz luasocket-9fc682a106f13901b60a665619fc61d9dae49fb0.tar.bz2 luasocket-9fc682a106f13901b60a665619fc61d9dae49fb0.zip |
HTTP now has only one function.
Diffstat (limited to 'src')
-rw-r--r-- | src/http.lua | 19 | ||||
-rw-r--r-- | src/url.lua | 3 |
2 files changed, 10 insertions, 12 deletions
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) | |||
122 | local u = reqt | 122 | local u = reqt |
123 | if not reqt.proxy and not PROXY then | 123 | if not reqt.proxy and not PROXY then |
124 | u = { | 124 | u = { |
125 | path = reqt.path, | 125 | path = socket.try(reqt.path, "invalid path 'nil'"), |
126 | params = reqt.params, | 126 | params = reqt.params, |
127 | query = reqt.query, | 127 | query = reqt.query, |
128 | fragment = reqt.fragment | 128 | fragment = reqt.fragment |
@@ -152,18 +152,15 @@ local default = { | |||
152 | 152 | ||
153 | local function adjustrequest(reqt) | 153 | local function adjustrequest(reqt) |
154 | -- parse url if provided | 154 | -- parse url if provided |
155 | if reqt.url then | 155 | local nreqt = reqt.url and url.parse(reqt.url, default) or {} |
156 | local parsed = url.parse(reqt.url, default) | 156 | -- explicit components override url |
157 | -- explicit components override url | 157 | for i,v in reqt do nreqt[i] = reqt[i] end |
158 | for i,v in parsed do reqt[i] = reqt[i] or v end | 158 | socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'") |
159 | end | ||
160 | socket.try(reqt.host, "invalid host '" .. tostring(reqt.host) .. "'") | ||
161 | socket.try(reqt.path, "invalid path '" .. tostring(reqt.path) .. "'") | ||
162 | -- compute uri if user hasn't overriden | 159 | -- compute uri if user hasn't overriden |
163 | reqt.uri = reqt.uri or uri(reqt) | 160 | nreqt.uri = nreqt.uri or uri(nreqt) |
164 | -- adjust headers in request | 161 | -- adjust headers in request |
165 | reqt.headers = adjustheaders(reqt.headers, reqt.host) | 162 | nreqt.headers = adjustheaders(nreqt.headers, nreqt.host) |
166 | return reqt | 163 | return nreqt |
167 | end | 164 | end |
168 | 165 | ||
169 | local function shouldredirect(reqt, code) | 166 | 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 | |||
115 | ----------------------------------------------------------------------------- | 115 | ----------------------------------------------------------------------------- |
116 | function parse(url, default) | 116 | function parse(url, default) |
117 | -- initialize default parameters | 117 | -- initialize default parameters |
118 | local parsed = default or {} | 118 | local parsed = {} |
119 | for i,v in (default or parsed) do parsed[i] = v end | ||
119 | -- empty url is parsed to nil | 120 | -- empty url is parsed to nil |
120 | if not url or url == "" then return nil, "invalid url" end | 121 | if not url or url == "" then return nil, "invalid url" end |
121 | -- remove whitespace | 122 | -- remove whitespace |