diff --git a/gateway/conf.d/apicast.conf b/gateway/conf.d/apicast.conf index 5cd1ce4e2..6bf89742a 100644 --- a/gateway/conf.d/apicast.conf +++ b/gateway/conf.d/apicast.conf @@ -10,49 +10,6 @@ lua_check_client_abort on; # ssl_session_fetch_by_lua_block { require('apicast.executor').call() } # ssl_session_store_by_lua_block { require('apicast.executor').call() } -location = /___http_call { - internal; - - set $url ''; - - set $proxy_pass ''; - set $host_header ''; - set $connection_header 'close'; - set $options ''; - set $grant_type ''; - - proxy_pass $proxy_pass; - proxy_pass_request_headers off; - proxy_pass_request_body on; - proxy_ssl_name $host_header; - proxy_http_version 1.1; - - proxy_set_header Host $host_header; - proxy_set_header Connection $connection_header; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-3scale-User-Agent $deployment; - proxy_set_header X-3scale-Version $version; - proxy_set_header User-Agent $user_agent; - proxy_set_header X-3scale-OAuth2-Grant-Type $grant_type; - proxy_set_header 3scale-options $options; - - # Hack for having a valid openresty config and valid liquid templating - #{% if opentracing_forward_header == nil or opentracing_forward_header == empty %} - # {% assign opentracing_forward_header = "uber-trace-id" %} - #{% endif %} - #{% if opentracing_tracer != nil or opentracing_forward_header != nil %} - # {% capture proxy_set_header_opentracing %} - #{#} proxy_set_header {{opentracing_forward_header}} $http_{{ opentracing_forward_header | tostring | replace: "-","_" }}; - # {% endcapture %} - # {{ proxy_set_header_opentracing | replace: "#{#}", "" }} - #{% endif %} - - rewrite_by_lua_block { - require('resty.http_ng.backend.ngx'):resolver() - } -} - location @out_of_band_authrep_action { internal; diff --git a/gateway/http.d/upstream.conf b/gateway/http.d/upstream.conf index 78f5507c7..c419ecf97 100644 --- a/gateway/http.d/upstream.conf +++ b/gateway/http.d/upstream.conf @@ -6,13 +6,3 @@ upstream upstream { keepalive 1024; keepalive_pool $upstream_keepalive_key; } - -upstream http_client { - server 0.0.0.1:1; - - balancer_by_lua_block { - require('resty.http_ng.backend.ngx'):balancer() - } - - keepalive 1024; -} diff --git a/gateway/src/resty/http_ng/backend/ngx.lua b/gateway/src/resty/http_ng/backend/ngx.lua deleted file mode 100644 index 1cd5902ab..000000000 --- a/gateway/src/resty/http_ng/backend/ngx.lua +++ /dev/null @@ -1,72 +0,0 @@ -local assert = assert -local backend = {} -local response = require 'resty.http_ng.response' -local Upstream = require('apicast.upstream') -local http_proxy = require 'resty.http.proxy' - -local METHODS = { - ["GET"] = ngx.HTTP_GET, - ["HEAD"] = ngx.HTTP_HEAD, - ["PATCH"] = ngx.HTTP_PATCH, - ["PUT"] = ngx.HTTP_PUT, - ["POST"] = ngx.HTTP_POST, - ["DELETE"] = ngx.HTTP_DELETE, - ["OPTIONS"] = ngx.HTTP_OPTIONS -} - -local PROXY_LOCATION = '/___http_call' -local pairs = pairs - -backend.capture = ngx.location.capture -backend.send = function(_, request) - if http_proxy.active(request) then - return response.error(request, 'ngx backend does not support proxy') - end - - local res = backend.capture(PROXY_LOCATION, { - method = METHODS[request.method], - body = request.body, - ctx = { - headers = request.headers, - url = request.url, - }, - vars = { - version = ngx.var.version, - } - }) - - -- if res.truncated then - -- Do what? what error message it should say? - -- end - - return response.new(request, res.status, res.header, res.body) -end - -local balancer = require('apicast.balancer') - -function backend.balancer() - return assert(balancer:call(ngx.ctx)) -end - -function backend.resolver() - local upstream = assert(Upstream.new(ngx.ctx.url)) - - upstream.upstream_name = 'http_client' - upstream.location_name = nil - - local headers = ngx.ctx.headers - - for name, _ in pairs(headers) do - ngx.req.set_header(name, headers[name]) - end - - ngx.req.set_uri('/') -- reset the original PROXY_LOCATION path - ngx.var.connection_header = headers.connection - ngx.var.host_header = headers.host - ngx.var.options = headers['3scale-options'] - ngx.var.grant_type = headers['X-3scale-OAuth2-Grant-Type'] - - upstream:call(ngx.ctx) -end - -return backend diff --git a/spec/resty/http_ng/backend/ngx_spec.lua b/spec/resty/http_ng/backend/ngx_spec.lua deleted file mode 100755 index f08de3217..000000000 --- a/spec/resty/http_ng/backend/ngx_spec.lua +++ /dev/null @@ -1,45 +0,0 @@ -local backend = require 'resty.http_ng.backend.ngx' - -describe('ngx backend',function() - describe('GET method', function() - local method = 'GET' - - before_each(function() ngx.var = { version = '0.1' } end) - - it('accesses the url', function() - backend.capture = function(location, options) - assert.equal('/___http_call', location) - assert.equal(ngx.HTTP_GET, options.method) - assert.are.same({version = '0.1'}, options.vars) - return { status = 200, body = '' } - end - local response = backend:send{method = method, url = 'http://localhost:8081' } - assert.truthy(response) - assert.truthy(response.request) - end) - - it('sends headers', function() - backend.capture = function(location, options) - assert.equal('/___http_call', location) - assert.equal(ngx.HTTP_GET, options.method) - assert.are.same({Host = 'fake.example.com'}, options.ctx.headers) - return { status = 200, body = '' } - end - local response = backend:send{method = method, url = 'http://localhost:8081/path', headers = {Host = 'fake.example.com'} } - assert.truthy(response) - assert.truthy(response.request) - end) - - context('http proxy is set', function() - before_each(function() - stub(require('resty.http.proxy'), 'active', true) - end) - - it('returns error', function() - local res = assert(backend:send{method = method, url = 'http://localhost:8081' }) - - assert.contains({ error = 'ngx backend does not support proxy' }, res) - end) - end) - end) -end)