Skip to content

Commit 5732afc

Browse files
SpyMachineGreg Kuruc
andauthored
Add support for path_as_is curlopt (#385)
Co-authored-by: Greg Kuruc <[email protected]>
1 parent c9a3e5f commit 5732afc

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

curl-sys/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ pub const CURLOPT_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 216;
587587
// pub const CURLOPT_LOGIN_OPTIONS: CURLoption = CURLOPTTYPE_OBJECTPOINT + 224;
588588
pub const CURLOPT_EXPECT_100_TIMEOUT_MS: CURLoption = CURLOPTTYPE_LONG + 227;
589589
pub const CURLOPT_UNIX_SOCKET_PATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 231;
590+
pub const CURLOPT_PATH_AS_IS: CURLoption = CURLOPTTYPE_LONG + 234;
590591
pub const CURLOPT_PIPEWAIT: CURLoption = CURLOPTTYPE_LONG + 237;
591592
pub const CURLOPT_CONNECT_TO: CURLoption = CURLOPTTYPE_OBJECTPOINT + 243;
592593
pub const CURLOPT_PROXY_CAINFO: CURLoption = CURLOPTTYPE_OBJECTPOINT + 246;

src/easy/handle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,11 @@ impl Easy {
563563
self.inner.connect_to(list)
564564
}
565565

566+
/// Same as [`Easy2::path_as_is`](struct.Easy2.html#method.path_as_is)
567+
pub fn path_as_is(&mut self, as_is: bool) -> Result<(), Error> {
568+
self.inner.path_as_is(as_is)
569+
}
570+
566571
/// Same as [`Easy2::proxy`](struct.Easy2.html#method.proxy)
567572
pub fn proxy(&mut self, url: &str) -> Result<(), Error> {
568573
self.inner.proxy(url)

src/easy/handler.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,12 +880,13 @@ impl<H> Easy2<H> {
880880
self.setopt_ptr(curl_sys::CURLOPT_CONNECT_TO, ptr as *const _)
881881
}
882882

883-
// /// Indicates whether sequences of `/../` and `/./` will be squashed or not.
884-
// ///
885-
// /// By default this option is `false` and corresponds to
886-
// /// `CURLOPT_PATH_AS_IS`.
887-
// pub fn path_as_is(&mut self, as_is: bool) -> Result<(), Error> {
888-
// }
883+
/// Indicates whether sequences of `/../` and `/./` will be squashed or not.
884+
///
885+
/// By default this option is `false` and corresponds to
886+
/// `CURLOPT_PATH_AS_IS`.
887+
pub fn path_as_is(&mut self, as_is: bool) -> Result<(), Error> {
888+
self.setopt_long(curl_sys::CURLOPT_PATH_AS_IS, as_is as c_long)
889+
}
889890

890891
/// Provide the URL of a proxy to use.
891892
///

tests/easy.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,3 +849,29 @@ fn test_upkeep() {
849849
// Ensure that upkeep can be called on the handle without problem.
850850
t!(handle.upkeep());
851851
}
852+
853+
#[test]
854+
fn path_as_is() {
855+
let s = Server::new();
856+
s.receive(
857+
"\
858+
GET /test/../ HTTP/1.1\r\n\
859+
Host: 127.0.0.1:$PORT\r\n\
860+
Accept: */*\r\n\
861+
\r\n",
862+
);
863+
s.send(
864+
"\
865+
HTTP/1.1 200 OK\r\n\
866+
\r\n",
867+
);
868+
869+
let mut h = handle();
870+
t!(h.url(&s.url("/test/../")));
871+
t!(h.path_as_is(true));
872+
t!(h.perform());
873+
874+
let addr = format!("http://{}/test/../", s.addr());
875+
assert_eq!(t!(h.response_code()), 200);
876+
assert_eq!(t!(h.effective_url()), Some(&addr[..]));
877+
}

0 commit comments

Comments
 (0)