Skip to content

Commit 97c0c46

Browse files
committed
fixes integration tests 1-10
fixed integration tests from 10 to 20 Signed-off-by: Samuele Illuminati <[email protected]> fixes integration tests & adds upstream http proxy patch fixes integration & unit tests
1 parent 2f65aba commit 97c0c46

File tree

4 files changed

+146
-149
lines changed

4 files changed

+146
-149
lines changed

gateway/src/apicast/http_proxy.lua

+2-9
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,9 @@ end
159159
function _M.request(upstream, proxy_uri)
160160
local uri = upstream.uri
161161

162-
if uri.scheme == 'http' then -- rewrite the request to use http_proxy
163-
local err
164-
local host = upstream:set_host_header()
165-
upstream:use_host_header(host)
166-
upstream.servers, err = resolve_servers(proxy_uri)
167-
if err then
168-
ngx.log(ngx.WARN, "HTTP proxy is set, but no servers have been resolved, err: ", err)
169-
end
170-
upstream.uri.path = absolute_url(uri)
162+
if uri.scheme == 'http' then
171163
upstream:rewrite_request()
164+
forward_https_request(proxy_uri, uri, upstream.skip_https_connect)
172165
return
173166
elseif uri.scheme == 'https' then
174167
upstream:rewrite_request()

gateway/src/resty/http/proxy.lua

+2-6
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ local function _connect_proxy_https(httpc, request, host, port)
7272
end
7373

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

@@ -95,11 +93,9 @@ local function connect_proxy(httpc, request, skip_https_connect)
9593
ngx.log(ngx.DEBUG, 'connection to ', proxy_uri.host, ':', proxy_uri.port, ' established',
9694
', pool: ', options.pool, ' reused times: ', httpc:get_reused_times())
9795

98-
ngx.log(ngx.DEBUG, 'targeting server ', uri.host, ':', uri.port)
99-
10096
if uri.scheme == 'http' then
10197
-- http proxy needs absolute URL as the request path
102-
request.path = format('%s://%s:%s%s', uri.scheme, uri.host, uri.port, uri.path or '/')
98+
request.path = format('%s://%s:%s%s', uri.scheme, uri.host, uri.port, uri.path or request.path or '/')
10399
return httpc
104100
elseif uri.scheme == 'https' and skip_https_connect then
105101
request.path = format('%s://%s:%s%s', uri.scheme, uri.host, uri.port, request.path or '/')
@@ -179,4 +175,4 @@ end
179175

180176
_M.new = connect
181177

182-
return _M:reset()
178+
return _M:reset()

spec/resty/http/proxy_spec.lua

+2-44
Original file line numberDiff line numberDiff line change
@@ -50,55 +50,13 @@ describe('resty.http.proxy', function()
5050
it('connects to the #http_proxy', function()
5151
_M:reset({ http_proxy = 'http://127.0.0.1:1984' })
5252

53-
local request = { url = 'http://127.0.0.1:1984/request', method = 'GET' }
53+
local request = { url = 'http://upstream:8091/request', method = 'GET' }
5454
local proxy = assert(_M.new(request))
5555

5656
local res = assert(proxy:request(request))
5757

5858
assert.same(200, res.status)
59-
assert.match('GET http://127.0.0.1:1984/request HTTP/1.1', res:read_body())
60-
end)
61-
62-
-- Regression test. Ref: https://issues.jboss.org/browse/THREESCALE-2205
63-
context('when different subdomains resolve to the same IP', function()
64-
local request_domain_1 = { url = 'http://test.example.com/', method = 'GET' }
65-
local request_domain_2 = { url = 'http://prod.example.com/', method = 'GET' }
66-
67-
before_each(function()
68-
-- Make everything resolve to the same IP
69-
local resty_resolver = require 'resty.resolver.http'
70-
stub(resty_resolver, 'resolve', function() return "1.1.1.1", 80 end)
71-
end)
72-
73-
context('and it uses a http proxy', function()
74-
before_each(function()
75-
_M:reset({ http_proxy = 'http://127.0.0.1:1984' })
76-
end)
77-
78-
it('does not reuse the connection', function()
79-
local proxy = _M.new(request_domain_1)
80-
proxy:request(request_domain_1):read_body()
81-
proxy:set_keepalive()
82-
83-
proxy = _M.new(request_domain_2)
84-
assert.same(0, proxy:get_reused_times())
85-
end)
86-
end)
87-
88-
context('and it does not use an http proxy', function()
89-
before_each(function()
90-
_M:reset({})
91-
end)
92-
93-
it('does not reuse the connection', function()
94-
local proxy = _M.new(request_domain_1)
95-
proxy:request(request_domain_1):read_body()
96-
proxy:set_keepalive()
97-
98-
proxy = _M.new(request_domain_2)
99-
assert.same(0, proxy:get_reused_times())
100-
end)
101-
end)
59+
assert.match('GET http://upstream:8091/request HTTP/1.1', res:read_body())
10260
end)
10361
end)
10462
end)

0 commit comments

Comments
 (0)