-
Notifications
You must be signed in to change notification settings - Fork 70
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
HTTPS support ? #3
Comments
HTTPS is not supported as the Lua Nginx module's cosockets do not support SSL. |
thanks chase for the quick answer. would you know any other alternative to HTTP post via SSL from lua nginx? |
I'm fairly certain you can make HTTPS requests using nginx's proxy_pass and a subrequest from Lua Nginx @leafo created an elagent solution use the aforementioned method. The code for proxy_http.moon roughly compiles to: -- proxy_http.lua
-- This implements LuaSocket's http.request on top of a proxy_pass within
-- nginx.
--
-- Add the following location to your server:
--
-- location /proxy {
-- internal;
-- rewrite_by_lua "
-- local req = ngx.req
-- req.clear_header'Cookie'
-- req.clear_header'Accept-Encoding'
-- req.clear_header'User-Agent'
-- if ngx.ctx.headers then
-- for k,v in pairs(ngx.ctx.headers) do
-- req.set_header(k, v)
-- end
-- end
-- ";
--
-- resolver 8.8.8.8;
-- proxy_pass $_url;
-- }
local ltn12 = require("ltn12")
local proxy_location = "/proxy"
local methods = {
["GET"] = ngx.HTTP_GET,
["HEAD"] = ngx.HTTP_HEAD,
["PUT"] = ngx.HTTP_PUT,
["POST"] = ngx.HTTP_POST,
["DELETE"] = ngx.HTTP_DELETE,
["OPTIONS"] = ngx.HTTP_OPTIONS
}
local set_proxy_location
set_proxy_location = function(loc)
proxy_location = loc
end
local request
request = function(url, str_body)
local return_res_body
local req
if type(url) == "table" then
req = url
else
return_res_body = true
req = {
url = url,
source = str_body and ltn12.source.string(str_body)
}
end
req.method = req.method or (req.source and "POST" or "GET")
local body
if req.source then
local buff = { }
local sink = ltn12.sink.table(buff)
ltn12.pump.all(req.source, sink)
body = table.concat(buff)
end
local res = ngx.location.capture(proxy_location, {
method = methods[req.method],
body = body,
ctx = {
headers = req.headers
},
vars = {
_url = req.url
}
})
local out
if return_res_body then
out = res.body
else
if req.sink then
ltn12.pump.all(ltn12.source.string(res.body), req.sink)
end
out = 1
end
return out, res.status, res.header
end
return {
request = request,
set_proxy_location = set_proxy_location
} |
good news!, it looks like @agentzh is looking at adding support for SSL for lua nginx module's cosocket (openresty/lua-nginx-module#178) |
i ll give that a try thanks chase! |
There were some issues with headers in the snippet above. I've fixed it. You can find the updated version here: https://github.com/leafo/heroku-openresty/wiki/Making-HTTP-Requests Also it's worth noting that with this method you can't use any hosts that are local to your system, like |
Starting from lua-nginx-module 0.9.11 cosockets support SSL openresty/lua-nginx-module#290 |
done |
Hi,
First let me congrats you with great lib. I was just wondering if HTTPS was supported ? i do not think to have any luck with it. i managed to get http working ok.
thanks
-seb
The text was updated successfully, but these errors were encountered: