mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-02-13 07:22:52 +01:00
Removed wrong host header in redirect.
Passing location header back to callee after redirect. Added correct scheme test.
This commit is contained in:
parent
84e503afe3
commit
164d33894e
14
src/http.lua
14
src/http.lua
@ -396,11 +396,11 @@ function Private.fill_headers(headers, parsed)
|
|||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
-- set default headers
|
-- set default headers
|
||||||
lower["user-agent"] = %Public.USERAGENT
|
lower["user-agent"] = %Public.USERAGENT
|
||||||
lower["host"] = parsed.host
|
|
||||||
-- override with user values
|
-- override with user values
|
||||||
for i,v in headers do
|
for i,v in headers do
|
||||||
lower[strlower(i)] = v
|
lower[strlower(i)] = v
|
||||||
end
|
end
|
||||||
|
lower["host"] = parsed.host
|
||||||
-- this cannot be overriden
|
-- this cannot be overriden
|
||||||
lower["connection"] = "close"
|
lower["connection"] = "close"
|
||||||
return lower
|
return lower
|
||||||
@ -482,7 +482,10 @@ function Private.redirect(request, response)
|
|||||||
body_cb = request.body_cb,
|
body_cb = request.body_cb,
|
||||||
headers = request.headers
|
headers = request.headers
|
||||||
}
|
}
|
||||||
return %Public.request_cb(redirect, response)
|
local response = %Public.request_cb(redirect, response)
|
||||||
|
-- we pass the location header as a clue we tried to redirect
|
||||||
|
if response.headers then response.headers.location = redirect.url end
|
||||||
|
return response
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@ -542,8 +545,13 @@ function Public.request_cb(request, response)
|
|||||||
local parsed = URL.parse_url(request.url, {
|
local parsed = URL.parse_url(request.url, {
|
||||||
host = "",
|
host = "",
|
||||||
port = %Public.PORT,
|
port = %Public.PORT,
|
||||||
path ="/"
|
path ="/",
|
||||||
|
scheme = "http"
|
||||||
})
|
})
|
||||||
|
if parsed.scheme ~= "http" then
|
||||||
|
response.error = format("unknown scheme '%s'", parsed.scheme)
|
||||||
|
return response
|
||||||
|
end
|
||||||
-- explicit authentication info overrides that given by the URL
|
-- explicit authentication info overrides that given by the URL
|
||||||
parsed.user = request.user or parsed.user
|
parsed.user = request.user or parsed.user
|
||||||
parsed.password = request.password or parsed.password
|
parsed.password = request.password or parsed.password
|
||||||
|
Loading…
x
Reference in New Issue
Block a user