-
Notifications
You must be signed in to change notification settings - Fork 108
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
Implement lua-http for HTTP(S) 1.0, 1.1 and 2.0 #594
Comments
And for luasec (needs to be updated for current master) set(PATCH_CMD sh -c "patch -N -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/redirects.patch || true") redirects.patch diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9976b19
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/src/*.o
+/src/luasocket/*.o
+/ssl.dll
diff --git a/src/https.lua b/src/https.lua
index c0594db..b7bb611 100644
--- a/src/https.lua
+++ b/src/https.lua
@@ -13,7 +13,6 @@ local http = require("socket.http")
local url = require("socket.url")
local table = require("table")
-local string = require("string")
local try = socket.try
local type = type
@@ -38,15 +37,10 @@ local cfg = {
-- Auxiliar Functions
--------------------------------------------------------------------
--- Insert default HTTPS port.
-local function default_https_port(u)
- return url.build(url.parse(u, {port = PORT}))
-end
-
-- Convert an URL to a table according to Luasocket needs.
local function urlstring_totable(url, body, result_table)
url = {
- url = default_https_port(url),
+ url = url,
method = body and "POST" or "GET",
sink = ltn12.sink.table(result_table)
}
@@ -81,9 +75,12 @@ local function tcp(params)
end
-- Force client mode
params.mode = "client"
+ -- upvalue to track https -> http redirection
+ local washttps = false
-- 'create' function for LuaSocket
return function (reqt)
- if (reqt.scheme or (url.parse(reqt.url or "") or {}).scheme) == "https" then
+ local u = url.parse(reqt.url)
+ if (reqt.scheme or u.scheme) == "https" then
-- https, provide an ssl wrapped socket
local conn = {}
conn.sock = try(socket.tcp())
@@ -99,12 +96,22 @@ local function tcp(params)
reg(self, getmetatable(self.sock))
return 1
end
+ -- insert https default port, overriding http port inserted by LuaSocket
+ if not u.port then
+ u.port = PORT
+ reqt.url = url.build(u)
+ reqt.port = PORT
+ end
+ washttps = true
return conn
else
-- regular http, needs just a socket...
+ if washttps and params.redirect ~= "all" then
+ try(nil, "Unallowed insecure redirect https to http")
+ end
return socket.tcp()
- end
- end
+ end
+ end
end
--------------------------------------------------------------------
@@ -124,16 +131,12 @@ function request(url, body)
local stringrequest = type(url) == "string"
if stringrequest then
url = urlstring_totable(url, body, result_table)
- else
- url.url = default_https_port(url.url)
end
if http.PROXY or url.proxy then
return nil, "proxy not supported"
- elseif url.create then
- return nil, "create function not permitted"
end
- -- New 'create' function to establish a secure connection
- url.create = tcp(url)
+ -- New 'create' function to establish the proper connection
+ url.create = url.create or tcp(url)
local res, code, headers, status = http.request(url)
if res and stringrequest then
return table.concat(result_table), code, headers, status |
I don't quite follow, but I'd like to move http library at least one step forward... how about using this lua http library: also found this : https://steve.fi/Software/lua/lua-httpd/ (client) but it's probably too simple. also fount howto for https +lua http://notebook.kulchenko.com/programming/https-ssl-calls-with-lua-and-luasec but we'd rather want library Just found this https://github.com/luvit/luvit does it mean we can use javascript (node.js) apps in lua? |
I tried above lua-httpclient but it doesn't solves our problems as I had: |
I must've missed this. :-) No, it looks like the Node.js API style in Lua. Which could still be quite interesting. |
Closing because redirects are now supported by Luasec 0.8 combined with up-to-date LuaSocket. See lunarmodules/luasec#132, lunarmodules/luasocket#268 and koreader/koreader#3516 (comment). |
See <koreader/koreader-base#594 (comment)>. LuaSocket takes care of everything now, so all similar code can be simplified.
See <koreader/koreader-base#594 (comment)>. LuaSocket takes care of everything now, so all similar code can be simplified.
See <koreader/koreader-base#594 (comment)>. LuaSocket takes care of everything now, so all similar code can be simplified.
See <koreader/koreader-base#594 (comment)>. LuaSocket takes care of everything now, so all similar code can be simplified.
See <koreader/koreader-base#594 (comment)>. LuaSocket takes care of everything now, so all similar code can be simplified.
Alternative lazy option, patch luasocket and luasec, see lunarmodules/luasec#38
parserequest.patch for luasocket updated for current master
The text was updated successfully, but these errors were encountered: