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
Copy file name to clipboardExpand all lines: README.md
+34-2
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,8 @@ Production ready.
22
22
23
23
*[new](#new)
24
24
*[connect](#connect)
25
+
*[connect_proxy](#connect_proxy)
26
+
*[set_proxy_options](#set_proxy_options)
25
27
*[set_timeout](#set_timeout)
26
28
*[set_timeouts](#set_timeouts)
27
29
*[ssl_handshake](#ssl_handshake)
@@ -158,6 +160,24 @@ An optional Lua table can be specified as the last argument to this method to sp
158
160
*`pool`
159
161
: 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:
168
+
169
+
*`proxy_uri` - Full URI of the proxy server to use (e.g. `http://proxy.example.com:3128/`). Note: Only `http` protocol is supported.
170
+
*`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.
171
+
*`host` - The hostname of the remote host to connect to.
172
+
*`port` - The port of the remote host to connect to.
173
+
174
+
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`.
175
+
176
+
There's a few key points to keep in mind when using this api:
177
+
178
+
* 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.
179
+
* 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`).
180
+
161
181
## set_timeout
162
182
163
183
`syntax: httpc:set_timeout(time)`
@@ -192,6 +212,18 @@ Note that calling this instead of `close` is "safe" in that it will conditionall
192
212
193
213
In case of success, returns `1`. In case of errors, returns `nil, err`. In the case where the conneciton is conditionally closed as described above, returns `2` and the error string `connection must be closed`.
194
214
215
+
## set_proxy_options
216
+
217
+
`syntax: httpc:set_proxy_options(opts)`
218
+
219
+
Configure an http proxy to be used with this client instance. The `opts` is a table that accepts the following fields:
220
+
221
+
*`http_proxy` - an URI to a proxy server to be used with http requests
222
+
*`https_proxy` - an URI to a proxy server to be used with https requests
223
+
*`no_proxy` - a comma separated list of hosts that should not be proxied.
224
+
225
+
Note that proxy options are only applied when using the high-level `request_uri()` API.
226
+
195
227
## get_reused_times
196
228
197
229
`syntax: times, err = httpc:get_reused_times()`
@@ -232,7 +264,7 @@ When the request is successful, `res` will contain the following fields:
232
264
*`status` The status code.
233
265
*`reason` The status reason phrase.
234
266
*`headers` A table of headers. Multiple headers with the same field name will be presented as a table of values.
235
-
*`has_body` A boolean flag indicating if there is a body to be read.
267
+
*`has_body` A boolean flag indicating if there is a body to be read.
236
268
*`body_reader` An iterator function for reading the body in a streaming fashion.
237
269
*`read_body` A method to read the entire body into a string.
238
270
*`read_trailers` A method to merge any trailers underneath the headers, after reading the body.
@@ -408,7 +440,7 @@ local res, err = httpc:request{
0 commit comments