Skip to content

Commit bc4f41a

Browse files
committed
[bitreq] Rename Proxy::new to Proxy::new_http
In the future we'd like to support SOCKS proxies as well, so get ahead of it by renaming `Proxy::new` to `Proxy::new_http` to allow us to have a `Proxy::new_socks5` in a point release.
1 parent 99acf70 commit bc4f41a

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

bitreq/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub enum Error {
6060
/// and as such, a connection cannot be made.
6161
HttpsFeatureNotEnabled,
6262
/// The provided proxy information was not properly formatted. See
63-
/// [Proxy::new](crate::Proxy::new) for the valid format.
63+
/// [Proxy](crate::Proxy) methods for the valid format.
6464
#[cfg(feature = "proxy")]
6565
BadProxy,
6666
/// The provided credentials were rejected by the proxy server.

bitreq/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
208208
//! #[cfg(feature = "proxy")]
209209
//! {
210-
//! let proxy = bitreq::Proxy::new("localhost:8080")?;
210+
//! let proxy = bitreq::Proxy::new_http("localhost:8080")?;
211211
//! let response = bitreq::post("http://example.com")
212212
//! .with_proxy(proxy)
213213
//! .send()?;

bitreq/src/proxy.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Proxy {
4141
}
4242
}
4343

44-
/// Creates a new Proxy configuration.
44+
/// Creates a new Proxy configuration for an HTTP proxy supporting the `CONNECT` command.
4545
///
4646
/// Supported proxy format is:
4747
///
@@ -54,11 +54,11 @@ impl Proxy {
5454
/// # Example
5555
///
5656
/// ```
57-
/// let proxy = bitreq::Proxy::new("user:password@localhost:1080").unwrap();
57+
/// let proxy = bitreq::Proxy::new_http("user:password@localhost:1080").unwrap();
5858
/// let request = bitreq::post("http://example.com").with_proxy(proxy);
5959
/// ```
6060
///
61-
pub fn new<S: AsRef<str>>(proxy: S) -> Result<Self, Error> {
61+
pub fn new_http<S: AsRef<str>>(proxy: S) -> Result<Self, Error> {
6262
let proxy = proxy.as_ref();
6363
let authority = if let Some((proto, auth)) = split_once(proxy, "://") {
6464
if proto != "http" {
@@ -141,7 +141,7 @@ mod tests {
141141

142142
#[test]
143143
fn parse_proxy() {
144-
let proxy = Proxy::new("user:p@ssw0rd@localhost:9999").unwrap();
144+
let proxy = Proxy::new_http("user:p@ssw0rd@localhost:9999").unwrap();
145145
assert_eq!(proxy.user, Some(String::from("user")));
146146
assert_eq!(proxy.password, Some(String::from("p@ssw0rd")));
147147
assert_eq!(proxy.server, String::from("localhost"));
@@ -150,7 +150,7 @@ mod tests {
150150

151151
#[test]
152152
fn parse_regular_proxy_with_protocol() {
153-
let proxy = Proxy::new("http://localhost:1080").unwrap();
153+
let proxy = Proxy::new_http("http://localhost:1080").unwrap();
154154
assert_eq!(proxy.user, None);
155155
assert_eq!(proxy.password, None);
156156
assert_eq!(proxy.server, String::from("localhost"));

bitreq/src/request.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,22 +393,22 @@ impl ParsedRequest {
393393
if let Ok(proxy) =
394394
std::env::var("https_proxy").map_err(|_| std::env::var("HTTPS_PROXY"))
395395
{
396-
if let Ok(proxy) = Proxy::new(proxy) {
396+
if let Ok(proxy) = Proxy::new_http(proxy) {
397397
config.proxy = Some(proxy);
398398
}
399399
}
400400
}
401401
// Set HTTP proxies if request's protocol is HTTP and they're given
402402
else if let Ok(proxy) = std::env::var("http_proxy") {
403-
if let Ok(proxy) = Proxy::new(proxy) {
403+
if let Ok(proxy) = Proxy::new_http(proxy) {
404404
config.proxy = Some(proxy);
405405
}
406406
}
407407
// Set any given proxies if neither of HTTP/HTTPS were given
408408
else if let Ok(proxy) =
409409
std::env::var("all_proxy").map_err(|_| std::env::var("ALL_PROXY"))
410410
{
411-
if let Ok(proxy) = Proxy::new(proxy) {
411+
if let Ok(proxy) = Proxy::new_http(proxy) {
412412
config.proxy = Some(proxy);
413413
}
414414
}

0 commit comments

Comments
 (0)