Skip to content

Commit 2c69a44

Browse files
authored
Add support for CURLOPT_CONNECT_TO (#348)
1 parent fc7510d commit 2c69a44

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

curl-sys/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ pub const CURLOPT_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 216;
576576
// pub const CURLOPT_LOGIN_OPTIONS: CURLoption = CURLOPTTYPE_OBJECTPOINT + 224;
577577
pub const CURLOPT_UNIX_SOCKET_PATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 231;
578578
pub const CURLOPT_PIPEWAIT: CURLoption = CURLOPTTYPE_LONG + 237;
579+
pub const CURLOPT_CONNECT_TO: CURLoption = CURLOPTTYPE_OBJECTPOINT + 243;
579580
pub const CURLOPT_PROXY_CAINFO: CURLoption = CURLOPTTYPE_OBJECTPOINT + 246;
580581
pub const CURLOPT_PROXY_CAPATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 247;
581582
pub const CURLOPT_PROXY_SSLCERT: CURLoption = CURLOPTTYPE_OBJECTPOINT + 254;

src/easy/handle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ impl Easy {
558558
self.inner.port(port)
559559
}
560560

561+
/// Same as [`Easy2::connect_to`](struct.Easy2.html#method.connect_to)
562+
pub fn connect_to(&mut self, list: List) -> Result<(), Error> {
563+
self.inner.connect_to(list)
564+
}
565+
561566
/// Same as [`Easy2::proxy`](struct.Easy2.html#method.proxy)
562567
pub fn proxy(&mut self, url: &str) -> Result<(), Error> {
563568
self.inner.proxy(url)

src/easy/handler.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ struct Inner<H> {
383383
handle: *mut curl_sys::CURL,
384384
header_list: Option<List>,
385385
resolve_list: Option<List>,
386+
connect_to_list: Option<List>,
386387
form: Option<Form>,
387388
error_buf: RefCell<Vec<u8>>,
388389
handler: H,
@@ -625,6 +626,7 @@ impl<H: Handler> Easy2<H> {
625626
handle: handle,
626627
header_list: None,
627628
resolve_list: None,
629+
connect_to_list: None,
628630
form: None,
629631
error_buf: RefCell::new(vec![0; curl_sys::CURL_ERROR_SIZE]),
630632
handler: handler,
@@ -885,6 +887,24 @@ impl<H> Easy2<H> {
885887
self.setopt_long(curl_sys::CURLOPT_PORT, port as c_long)
886888
}
887889

890+
/// Connect to a specific host and port.
891+
///
892+
/// Each single string should be written using the format
893+
/// `HOST:PORT:CONNECT-TO-HOST:CONNECT-TO-PORT` where `HOST` is the host of
894+
/// the request, `PORT` is the port of the request, `CONNECT-TO-HOST` is the
895+
/// host name to connect to, and `CONNECT-TO-PORT` is the port to connect
896+
/// to.
897+
///
898+
/// The first string that matches the request's host and port is used.
899+
///
900+
/// By default, this option is empty and corresponds to
901+
/// [`CURLOPT_CONNECT_TO`](https://curl.haxx.se/libcurl/c/CURLOPT_CONNECT_TO.html).
902+
pub fn connect_to(&mut self, list: List) -> Result<(), Error> {
903+
let ptr = list::raw(&list);
904+
self.inner.connect_to_list = Some(list);
905+
self.setopt_ptr(curl_sys::CURLOPT_CONNECT_TO, ptr as *const _)
906+
}
907+
888908
// /// Indicates whether sequences of `/../` and `/./` will be squashed or not.
889909
// ///
890910
// /// By default this option is `false` and corresponds to

systest/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ fn main() {
124124
}
125125

126126
if version < 49 {
127-
if s.starts_with("CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE") {
128-
return true;
127+
match s {
128+
"CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE" | "CURLOPT_CONNECT_TO" => return true,
129+
_ => {}
129130
}
130131
}
131132

0 commit comments

Comments
 (0)