Add ClientBuilder::local_address option to bind to a local IP address (#451)

Closes #414
This commit is contained in:
Michael Habib
2019-02-11 10:40:16 -08:00
committed by Sean McArthur
parent 8ed9e60351
commit 4dc679d535
3 changed files with 60 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ use std::fmt;
use std::sync::Arc;
use std::time::Duration;
use std::thread;
use std::net::IpAddr;
use futures::{Async, Future, Stream};
use futures::future::{self, Either};
@@ -306,6 +307,24 @@ impl ClientBuilder {
pub fn h2_prior_knowledge(self) -> ClientBuilder {
self.with_inner(|inner| inner.h2_prior_knowledge())
}
/// Bind to a local IP Address
///
/// # Example
///
/// ```
/// use std::net::IpAddr;
/// let local_addr = IpAddr::from([12, 4, 1, 8]);
/// let client = reqwest::Client::builder()
/// .local_address(local_addr)
/// .build().unwrap();
/// ```
pub fn local_address<T>(self, addr: T) -> ClientBuilder
where
T: Into<Option<IpAddr>>,
{
self.with_inner(move |inner| inner.local_address(addr))
}
}