Skip to content

Commit 907db14

Browse files
authored
Merge pull request #1478 from tkan145/THREESCALE-11128-no-proxy
Prevent APIcast fallback to global proxy settings for direct connection
2 parents b75d3b8 + d4550af commit 907db14

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Fixed 3scale Batcher policy unable to handle `app_id`/`access_token` contains special characters [PR #1457](https://github.com/3scale/APIcast/pull/1457) [THREESCALE-10934](https://issues.redhat.com/browse/THREESCALE-10934)
1313

14+
- Fixed APIcast send request through proxy server even when `NO_PROXY` is used [PR #1478](https://github.com/3scale/APIcast/pull/1478) [THREESCALE-11128](https://issues.redhat.com/browse/THREESCALE-11128)
15+
1416
### Added
1517

1618
- Bump openresty to 1.21.4.3 [PR #1461](https://github.com/3scale/APIcast/pull/1461) [THREESCALE-10601](https://issues.redhat.com/browse/THREESCALE-10601)

gateway/src/resty/http/proxy.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ local function connect(request)
5757
-- openresty treat nil as false, so we need to explicitly set ssl_verify to false if nil
5858
local ssl_verify = request.options and request.options.ssl and request.options.ssl.verify or false
5959

60+
-- We need to set proxy_opts to an empty table here otherwise, lua-resty-http will fallback
61+
-- to the global proxy options
6062
local options = {
6163
scheme = scheme,
6264
host = host,
63-
port = port
65+
port = port,
66+
proxy_opts = {}
6467
}
6568
if scheme == 'https' then
6669
options.ssl_server_name = host

t/http-proxy.t

+43
Original file line numberDiff line numberDiff line change
@@ -2083,3 +2083,46 @@ qr/a client request body is buffered to a temporary file/
20832083
--- grep_error_log_out
20842084
a client request body is buffered to a temporary file
20852085
--- user_files fixture=tls.pl eval
2086+
2087+
2088+
2089+
=== TEST 36: APIcast should not ingore NO_PROXY, when HTTP_PROXY and HTTPS_PROXY are also set
2090+
It connects directly to backened and forwards request to the upstream via proxy.
2091+
--- env random_port eval
2092+
(
2093+
'http_proxy' => $ENV{TEST_NGINX_HTTP_PROXY},
2094+
'no_proxy' => '127.0.0.1,localhost,test_backend',
2095+
)
2096+
--- configuration
2097+
{
2098+
"services": [
2099+
{
2100+
"id": 42,
2101+
"backend_version": 1,
2102+
"proxy": {
2103+
"api_backend": "http://test-upstream.lvh.me:$TEST_NGINX_SERVER_PORT/",
2104+
"proxy_rules": [
2105+
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
2106+
]
2107+
}
2108+
}
2109+
]
2110+
}
2111+
--- backend
2112+
server_name test_backend.lvh.me;
2113+
location /transactions/authrep.xml {
2114+
content_by_lua_block {
2115+
ngx.exit(ngx.OK)
2116+
}
2117+
}
2118+
--- upstream
2119+
server_name test-upstream.lvh.me;
2120+
location / {
2121+
echo 'yay, api backend: $http_host';
2122+
}
2123+
--- request
2124+
GET /?user_key=value
2125+
--- response_body env
2126+
yay, api backend: test-upstream.lvh.me:$TEST_NGINX_SERVER_PORT
2127+
--- error_code: 200
2128+
--- no_error_log

0 commit comments

Comments
 (0)