Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
- skip_https_connect as request attribute
- http_proxy not used attribute http_backend removed
  • Loading branch information
eguzki committed Feb 2, 2024
1 parent cbdf78a commit ee07ae5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions gateway/src/apicast/http_proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ local DEFAULT_CHUNKSIZE = 32 * 1024

function _M.reset()
_M.resolver = resty_resolver
_M.http_backend = require('resty.http_ng.backend.resty')
_M.dns_resolution = 'apicast' -- can be set to 'proxy' to let proxy do the name resolution

return _M
Expand Down Expand Up @@ -157,10 +156,11 @@ local function forward_https_request(proxy_uri, uri, proxy_opts)
body = body,
proxy_uri = proxy_uri,
proxy_auth = opts.proxy_auth,
upstream_connection_opts = opts.upstream_connection_opts
upstream_connection_opts = opts.upstream_connection_opts,
skip_https_connect = opts.skip_https_connect
}

local httpc, err = http_proxy.new(request, opts.skip_https_connect)
local httpc, err = http_proxy.new(request)

if not httpc then
ngx.log(ngx.ERR, 'could not connect to proxy: ', proxy_uri, ' err: ', err)
Expand Down
8 changes: 4 additions & 4 deletions gateway/src/resty/http/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ local function _connect_proxy_https(httpc, request, host, port)
return httpc
end

local function connect_proxy(httpc, request, skip_https_connect)
local function connect_proxy(httpc, request)
-- target server requires hostname not IP and DNS resolution is left to the proxy itself as specified in the RFC #7231
-- https://httpwg.org/specs/rfc7231.html#CONNECT
local uri = request.uri
local proxy_uri = request.proxy
local skip_https_connect = request.skip_https_connect

if proxy_uri.scheme ~= 'http' then
return nil, 'proxy connection supports only http'
Expand Down Expand Up @@ -109,7 +110,6 @@ local function connect_proxy(httpc, request, skip_https_connect)
return _connect_tls_direct(httpc, request, uri.host, uri.port)
elseif uri.scheme == 'https' then
return _connect_proxy_https(httpc, request, uri.host, uri.port)

else
return nil, 'invalid scheme'
end
Expand All @@ -130,7 +130,7 @@ local function find_proxy_url(request)
return request.proxy_uri or _M.find(uri)
end

local function connect(request, skip_https_connect)
local function connect(request)
request = request or { }
local opts = { timeouts = request.upstream_connection_opts }
local httpc = http.new(opts)
Expand All @@ -140,7 +140,7 @@ local function connect(request, skip_https_connect)
request.proxy = proxy_uri

if proxy_uri then
return connect_proxy(httpc, request, skip_https_connect)
return connect_proxy(httpc, request)
else
return connect_direct(httpc, request)
end
Expand Down

0 comments on commit ee07ae5

Please sign in to comment.