Skip to content

Commit 8146ab3

Browse files
committed
Merge pull request #15 from carllerche/proxy-support
Initial proxy support
2 parents 2bfba17 + fcc7a9d commit 8146ab3

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/http/handle.rs

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ impl Handle {
3131
self
3232
}
3333

34+
pub fn proxy<U: ToUrl>(mut self, proxy: U) -> Handle {
35+
proxy.with_url_str(|s| {
36+
self.easy.setopt(opt::PROXY, s).unwrap();
37+
});
38+
39+
self
40+
}
41+
3442
pub fn get<'a, 'b, U: ToUrl>(&'a mut self, uri: U) -> Request<'a, 'b> {
3543
Request::new(self, Get).uri(uri)
3644
}

src/test/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ macro_rules! wait(
2626
mod get;
2727
mod head;
2828
mod post;
29+
mod proxy;
2930
mod put;
3031
mod delete;
3132
mod keep_alive;

src/test/proxy.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use http;
2+
use super::server;
3+
4+
#[test]
5+
pub fn test_proxy() {
6+
let srv = server!(
7+
recv!(b"POST http://www.google.com HTTP/1.1\r\n\
8+
Host: www.google.com\r\n\
9+
Accept: */*\r\n\
10+
Proxy-Connection: Keep-Alive\r\n\
11+
Content-Type: application/octet-stream\r\n\
12+
Content-Length: 11\r\n\
13+
\r\n\
14+
Foo Bar Baz"),
15+
send!(b"HTTP/1.1 200 OK\r\n\
16+
Content-Length: 5\r\n\r\n\
17+
Hello\r\n\r\n"));
18+
19+
let res = http::handle()
20+
.proxy(server::url("/"))
21+
.post("http://www.google.com", "Foo Bar Baz")
22+
.exec().unwrap();
23+
24+
srv.assert();
25+
26+
assert!(res.get_code() == 200);
27+
assert!(res.get_body() == "Hello".as_bytes());
28+
}

0 commit comments

Comments
 (0)