-
-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What sequence of API calls should be made when calling through HTTP Proxy? #288
Comments
I think perhaps you are somehow confusing "single-shot vs streaming", with "proxy vs direct". The You are able to use |
Ok I understand. So theoretically there should be only one call to I tried the below code but it fails when calling the
I am unable to figure out what is the problem. The code is as below if conf.proxy_uri then
kong.log.notice("Setting the proxy options")
local proxy_opts = {
http_proxy = conf.proxy_uri,
https_proxy = conf.proxy_uri
}
httpc:set_proxy_options(proxy_opts)
kong.log.notice("Setting the proxy options....done")
end
local connect_opts = {
scheme = scheme,
host = host,
port = port
}
httpc:connect(connect_opts)
kong.log.notice("Making http request")
res, err = httpc:request(auth_request) |
Well, the error message shows that the code fails when trying to treat a variable as a string, when it is I guess we should detect something as simple as that to give a better error message, instead of crashing. PR's welcome! p.s, the idea with the new (smarter) connect mechanism is that you should just be able to put all of your config in one table, and call p.p.s, there are definitely other Kong plugins that do this. Perhaps they are enterprise only, I don't remember. But you might find working example code if you look around. |
Thanks for helping on the troubleshooting but I verified the variable values - I didn't post the complete code because it has much more other things that would confuse the discussion. I am sharing the recent logs and the code for ease.
The code is as below function _M.execute(conf)
local res, ok, err
local scheme, host, port, path = unpack(http:parse_uri(conf.uam_check_token_api))
local auth_request = _M.new_auth_request(
host, port, path, token, institution_name, conf.timeout_ms)
local httpc = http.new()
httpc:set_timeout(conf.timeout_ms)
if conf.proxy_uri then
kong.log.notice("Setting the proxy options")
local proxy_opts = {
http_proxy = conf.proxy_uri,
https_proxy = conf.proxy_uri
}
httpc:set_proxy_options(proxy_opts)
kong.log.notice("Setting the proxy options....done")
end
kong.log.notice("Scheme : " .. scheme .. " Host : " .. host .. " Port : " .. port)
local connect_opts = {
scheme = scheme,
host = host,
port = port
}
httpc:connect(connect_opts)
kong.log.notice("Making http request")
res, err = httpc:request(auth_request)
kong.log.notice("HTTP call done")
end
function _M.new_auth_request(host, port, path, token, inst, timeout_ms)
local payload = '{ "sToken": "' .. token }'
return {
method = "POST",
path = path,
headers = headers,
body = payload,
keepalive_timeout = timeout_ms,
ssl_verify = false
}
end |
Judging from your error logs, it is crashing on the Again, without full code, I'm left guessing. Please create a minimal reproducible test case that someone else can try out, and we can go from there. Usually, in doing so, you'll discover what you're doing wrong ;) |
I am using openresty http library (v0.16.1) inside a custom kong plugin. I need to make an api call through a http proxy if it is configured. So my current code looks as below -
The sequence of api calls made when going through proxy are
While the sequence of api calls made when directly calling the remote host are
Below are my questions
connect
when going through the proxy?Thanks.
The text was updated successfully, but these errors were encountered: