diff --git a/CHANGELOG.md b/CHANGELOG.md index 183a21e68..9451e8ce4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Docker compose up instead of docker compose run [PR #1442](https://github.com/3scale/APIcast/pull/1442) - Fix integration of upstream connection policy with camel policy [PR #1443](https://github.com/3scale/APIcast/pull/1443) [THREESCALE-10582](https://issues.redhat.com/browse/THREESCALE-10582) + - Upgrade lua-resty-http to 0.17.1 to fix 100 response header are not handled when using `HTTPS_PROXY` [PR #1434](https://github.com/3scale/APIcast/pull/1434) [THREESCALE-10278](https://issues.redhat.com/browse/THREESCALE-10278) ### Added diff --git a/gateway/src/resty/http/proxy.lua b/gateway/src/resty/http/proxy.lua index fb88bb79f..40ea28c88 100644 --- a/gateway/src/resty/http/proxy.lua +++ b/gateway/src/resty/http/proxy.lua @@ -75,12 +75,12 @@ local function connect(request) proxy_uri.port = default_port(proxy_uri) end - -- Resolve the proxy IP/Port - local proxy_host, proxy_port = httpc:resolve(proxy_uri.host, proxy_uri.port) - local proxy_url = format("%s://%s:%s", proxy_uri.scheme, proxy_host, proxy_port) + local proxy_url = format("%s://%s:%s", proxy_uri.scheme, proxy_uri.host, proxy_uri.port) local proxy_auth = request.proxy_auth if scheme == 'http' then + -- Used by http_ng module to send request to 3scale backend through proxy. + -- http proxy needs absolute URL as the request path, lua-resty-http 1.17.1 will -- construct a path_prefix based on host and port so we only set request path here -- @@ -128,6 +128,7 @@ local function connect(request) ngx.log(ngx.DEBUG, 'targeting server ', host, ':', port) else -- Connect direct + -- Mostly used by http_ng module to connect 3scale backend module. local ok, err = httpc:connect(options) if not ok then return nil, err end diff --git a/gateway/src/resty/resolver/http.lua b/gateway/src/resty/resolver/http.lua index c08db8263..4f646ffbc 100644 --- a/gateway/src/resty/resolver/http.lua +++ b/gateway/src/resty/resolver/http.lua @@ -1,6 +1,8 @@ local resty_http = require 'resty.http' local resty_resolver = require 'resty.resolver' local round_robin = require 'resty.balancer.round_robin' +local url_helper = require('resty.url_helper') +local format = string.format local setmetatable = setmetatable @@ -53,6 +55,21 @@ function _M.connect(self, options, ...) ip, real_port = self:resolve(options.host, options.port) options.host = ip options.port = real_port + else + local proxy_uri, err = url_helper.parse_url(proxy) + if not proxy_uri then + return nil, 'invalid proxy: ' .. err + end + + -- Resolve the proxy IP/Port + local proxy_host, proxy_port = self:resolve(proxy_uri.host, proxy_uri.port) + local proxy_url = format("%s://%s:%s", proxy_uri.scheme, proxy_host, proxy_port) + + if proxy_opts.http_proxy then + options.proxy_opts.http_proxy = proxy_url + elseif proxy_opts.https_proxy then + options.proxy_opts.https_proxy = proxy_url + end end local ok, err = resty_http.connect(self, options, ...)