canary1

  local headers=ngx.req.get_headers()
  local ip=headers["X-REAL-IP"] or headers["X_FORWARDED_FOR"] or ngx.var.remote_addr or "0.0.0.0"
  kong.log.notice('Canary request ip1  is ',ip);
  local binary_remote_addr = ngx.var.binary_remote_addr
  kong.log.notice('Canary request ip2  is ',binary_remote_addr);

  get_client_ip();
  local client_ip = get_client_ip();

  local url = "http://106.54.100.29:10005/user/status?uname=hml"
  local res = httpGet.getUrl(url)
  if res == nil then
    kong.log.notice("请求GrayRule异常:",ngx.WARN,"非200状态,code:", code);
  end

  if res then
    -- 从灰度规则服务判断当当前请求是灰度IP
    kong.log.notice("请求GrayRule成功,当前IP灰度状态:",res);
    return true, nil;
  else
    kong.log.notice("请求GrayRule成功,当前IP灰度状态:",res);
    return false, nil;
  end
local http = require("socket.http")
local ltn12 = require("ltn12")

local httpGet = {}

function http.get(u)
    local t = {}
    local r, c, h = http.request{
        url = u,
        sink = ltn12.sink.table(t)}
    return r, c, h, table.concat(t)
end

-- 发送http.get请求,返回响应结果
function httpGet:getUrl(url)
    r,c,h,body = http.get(url)
    if c~= 200 then
        kong.log.notice('ErrorCode: ',c);
        return
    else
        kong.log.notice('返回结果: ',body);
        return body
    end
end

return httpGet;


-- url = "http://www.baidu.com"
-- body = wb_getUrl(url)
-- if body ~= nil then
--    writeFile("baidu.html", body)
-- end

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值