You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
followup: separate proxy connection setup logic to a low-level connect_proxy() method
This commit separates the logic that sets up the connection to the proxy server
to a separate connect_proxy() method. This method is provided to users as a
low-level API they can use similarly to the connect() method.
The connect_proxy() will handle the connection establishment to the proxy server
and performs the CONNECT request to setup a TCP tunnel to a https protected host.
Similar to the connect() method, it is then up to the user to take care of the
details that are relevant when using a proxy (i.e use absolute uris for http
requests and perform a TLS handshake for https connections).
There's also a new test case that verifies the CONNECT request is used properly
to establish a tunnel to the remote server when TLS is used. Due to the limitations
of the test framework, this case only considers the format of the outgoing CONNECT
request and how the code handles errors sent by the proxy. Testing a full TLS tunnel
is unfortunately not possible with the tools the test framework provides as it would
require a real reverse proxy or a method of forwarding the TCP connection after the
CONNECT request is received to a real web server that can talk TLS.
Copy file name to clipboardExpand all lines: README.md
+21-2Lines changed: 21 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@ Production ready.
22
22
23
23
*[new](#new)
24
24
*[connect](#connect)
25
+
*[connect_proxy](#connect_proxy)
25
26
*[set_timeout](#set_timeout)
26
27
*[set_timeouts](#set_timeouts)
27
28
*[ssl_handshake](#ssl_handshake)
@@ -158,6 +159,24 @@ An optional Lua table can be specified as the last argument to this method to sp
158
159
*`pool`
159
160
: Specifies a custom name for the connection pool being used. If omitted, then the connection pool name will be generated from the string template `<host>:<port>` or `<unix-socket-path>`.
Attempts to connect to the web server through the given proxy server. The method accepts the following arguments:
167
+
168
+
*`proxy_uri` - Full URI of the proxy server to use (e.g. `http://proxy.example.com:3128/`). Note: Only `http` protocol is supported.
169
+
*`scheme` - The protocol to use between the proxy server and the remote host (`http` or `https`). If `https` is specified as the scheme, `connect_proxy()` makes a `CONNECT` request to establish a TCP tunnel to the remote host through the proxy server.
170
+
*`host` - The hostname of the remote host to connect to.
171
+
*`port` - The port of the remote host to connect to.
172
+
173
+
If an error occurs during the connection attempt, this method returns `nil` with a string describing the error. If the connection was successfully established, the method returns `1`.
174
+
175
+
There's a few key points to keep in mind when using this api:
176
+
177
+
* If the scheme is `https`, you need to perform the TLS handshake with the remote server manually using the `ssl_handshake()` method before sending any requests through the proxy tunnel.
178
+
* If the scheme is `http`, you need to ensure that the requests you send through the connections conforms to [RFC 7230](https://tools.ietf.org/html/rfc7230) and especially [Section 5.3.2.](https://tools.ietf.org/html/rfc7230#section-5.3.2) which states that the request target must be in absolute form. In practice, this means that when you use `send_request()`, the `path` must be an absolute URI to the resource (e.g. `http://example.com/index.html` instead of just `/index.html`).
179
+
161
180
## set_timeout
162
181
163
182
`syntax: httpc:set_timeout(time)`
@@ -244,7 +263,7 @@ When the request is successful, `res` will contain the following fields:
244
263
*`status` The status code.
245
264
*`reason` The status reason phrase.
246
265
*`headers` A table of headers. Multiple headers with the same field name will be presented as a table of values.
247
-
*`has_body` A boolean flag indicating if there is a body to be read.
266
+
*`has_body` A boolean flag indicating if there is a body to be read.
248
267
*`body_reader` An iterator function for reading the body in a streaming fashion.
249
268
*`read_body` A method to read the entire body into a string.
250
269
*`read_trailers` A method to merge any trailers underneath the headers, after reading the body.
@@ -420,7 +439,7 @@ local res, err = httpc:request{
0 commit comments