-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support HTTP(S) redirect #34
Comments
It is not easy without import more code from LuaSocket. LuaSec use the "create" parameter on http.request(). The problem is: "create" does not inform if you will connect with a host using http or https. If you connect to a host using https and you receive a redirect "http://...", it will break, because LuaSec's "create" only create ssl/tls connections. https://github.com/diegonehab/luasocket/blob/master/src/http.lua#L109 In order to work, LuaSocket must give more information to "create" as parameter, or LuaSec import the code that detects redirect from LuaSocket. https://github.com/diegonehab/luasocket/blob/master/src/http.lua#L320 |
Music Man almost forgot escape go back to you in a 51
|
Coding the solution isn't the biggest problem I think. My concerns are about redirects that reduce security. I think that a redirect from I don't know security that well, but I can also imagine a redirect that still is |
See lunarmodules/luasocket#133 for a fix to allow redirecting over protocols. |
I was asking for |
The other way around is certainly normal. Anyway, one needs to have them covered. But as it currently is, the code should allow for redirects https -> https. Did you test before posting this issue? |
This is my simple example: https = require "ssl.https"
function show_html(url)
local response, code, headers, status = https.request(url)
if code ~= 200 then
print ("Response :", response)
print ("HTTP Code :", code)
print ("Headers :", headers)
print ("Status :", status)
return nil
end
print(response)
end
show_html("https://goo.gl/UBCUc5") Get And this is one with options as param: https = require "ssl.https"
ltn12 = require "ltn12"
function download_to_file(url, file_path)
print("url to download: "..url)
local respbody = {}
local options = {
url = url,
sink = ltn12.sink.table(respbody),
redirect = false
}
local response = nil
response = {https.request(options)}
-- nil, code, headers, status
local code = response[2]
local headers = response[3]
local status = response[4]
if code ~= 200 then
print ("HTTP Code :", code)
print ("Headers :", headers)
print ("Status :", status)
return nil
end
print("Saved to: "..file_path)
file = io.open(file_path, "w+")
file:write(table.concat(respbody))
file:close()
return file_path
end
download_to_file("https://goo.gl/UBCUc5", "/tmp/test.html") code is 301, the good part is I can implement the redirection by my own, but it would be nice if the lib do the magic. |
I can confirm the problem (after testing the simple example). But it is not related to the problem I identified in #35. Internally the same |
Finally had some time to sort this one out. The problem was not with LuaSec. The redirect url, doesn't have a port number. So the default LuaSocket behaviour is to insert port 80. Which obviously fails with a https call. I think this can be closed in favour of #38. |
Thanks, great job. 👍 |
As I see, redirect is not supported. It is possible you support it?
https://github.com/brunoos/luasec/blob/master/src/https.lua#L123
Thanks.
The text was updated successfully, but these errors were encountered: