Skip to content

Instantly share code, notes, and snippets.

@badri
Created April 27, 2022 06:59
Show Gist options
  • Save badri/e72b6b45fe0ca25aa2ebd00e1eb70d22 to your computer and use it in GitHub Desktop.
Save badri/e72b6b45fe0ca25aa2ebd00e1eb70d22 to your computer and use it in GitHub Desktop.
local base64 = require "ngx.base64"
local httpc = require("resty.http").new()
local base64_encode = base64.encode_base64url
local proxy_opts = {}
local auth_header = "Basic " .. base64_encode("holosix:xN186VaYjrCGepJI")
proxy_opts.http_proxy_authorization = auth_header
proxy_opts.http_proxy_authorization = auth_header
proxy_opts.http_proxy = "http://squid.kong-dp.svc.cluster.local:3128"
proxy_opts.http_proxy = "http://squid.kong-dp.svc.cluster.local:3128"
local ok, err = httpc:connect {
scheme = "http",
host = "google.com",
port = "443",
proxy_opts = proxy_opts,
ssl_verify = false,
}
if not ok then
ngx.log(ngx.ERR, "unable to connect to proxy: ", err)
return
end
local res, err = httpc:request({
method = "GET",
path = "/",
})
if not ok then
ngx.log(ngx.ERR, "unable to connect to proxy: ", err)
return
end
local status = res.status
local length = res.headers["Content-Length"]
local body = res.body
ngx.log(ngx.ERR, "response body: ", body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment