local _M = {_VERSION = '1.0'}
local location_capture = ngx.location.capture
local ngx_var = ngx.var
local ngx_exec = ngx.exec
local ngx_HTTP_OK = ngx.HTTP_OK
local ngx_HTTP_GET = ngx.HTTP_GET
-- 输出响应内容体 (内容体结束后,再输出一个换行符).
local ngx_say = ngx.say
-- 输出响应内容体 (内容体结束后,不输出换行符).
local ngx_print = ngx.print
function _M:capture()
local options = {
method = ngx_HTTP_GET,
vars = {
my_upstream = 'http://remote8111',
my_uri = '/hello'
}
}
local res = location_capture('/upstream', options)
if res and res.status == ngx_HTTP_OK then
ngx_print(res.body)
return
end
ngx_say('capture failed')
end
function _M:exec()
ngx_var.my_upstream = 'http://remote8112'
ngx_var.my_uri = '/world'
ngx_exec('/upstream')
end
return _M