-
-
Notifications
You must be signed in to change notification settings - Fork 626
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
How can I use Proxy to send HTTP requests? #63
Comments
@prehawk1999 did u get a solution? I need this feature too. |
@prehawk1999 原来是自己人 有没有找到解决方案 |
@kaporzhu Use low level api: http:connect and http:request, use http:connect to connect proxy, and http:request to perform actual request. |
@prehawk1999 that's exactly the way I tried this afternoon. It seems I need to check it again. Thanks for ur help. |
@kaporzhu If the origin server expects only HTTPS few extra steps need to be considered. See RFC2817 https://tools.ietf.org/html/rfc2817. Just 2 cents. |
@iriyak thanks for your info :=) http is enough for my app. |
@kaporzhu Good to know that HTTP was sufficient in your use case. :) It wasn't to my use case that required HTTPS and I am going to post a new issue to cope with. |
@prehawk1999 can you please post a simple code to show how to perform the request by proxy?
|
The origin server can be connected via HTTP or you need to establish HTTPS connection? |
@iriyak Thank you very much for your reply, the HTTP would be enough for my app, but I'm in a private network, and all HTTP request need to be made by a proxy like: http://proxy.oa.com:8080, how can I do that? Thank you once more for your time |
@MrLeex Right, give me some while to prepare. For your information, key points to consider for going through a non-transparent forwarding proxy include:
More to come later. |
@iriyak Hi, I really appreciate your help, the absolute-form URI fixed my issue, so just set the path to the absolute URI will works great. To help other people why may have encountered this issue, here is how you can make request via proxy with lua-resty-http:
But there is still two questions:
|
@MrLeex When dealing with https proxy, or redirect, details should be manipulate by yourself. local res, err = instance.httpc:request(
{
version = 1.1,
method = "CONNECT",
headers = req_headers,
path = tostring(url_host) .. ":" .. tostring(url_port),
}
) For example, when proxys https, you should send CONNECT request , and then do Redirect is a much more simple case, as you should only deal with 3xx requests and resend. |
@prehawk1999 thanks for your help, gonna try it |
@MrLeex Yes, RFC2817 Section 5.2 describes the formal specification for establishing a tunneling with CONNECT. Now that multiple HTTP sessions must be handled in your app it is highly recommended to check res, err and add some error handling logic. While my debugging I have experienced a connection timed out caused by set_timeout(), 400/500/504 by the proxy while/after establishing a tunnel. Just 2 cents |
I'm using ngx.thread and lua-resty-http to send multiple request, and I want them all go through a proxy, what is the best way to do that?
The text was updated successfully, but these errors were encountered: