small improvements to docs
This commit is contained in:
		| @@ -35,30 +35,18 @@ pub struct Client { | |||||||
|     inner: ClientHandle, |     inner: ClientHandle, | ||||||
| } | } | ||||||
|  |  | ||||||
| /// A `ClientBuilder` can be used to create a `Client` with  custom configuration: | /// A `ClientBuilder` can be used to create a `Client` with  custom configuration. | ||||||
| /// | /// | ||||||
| /// - with hostname verification disabled | /// # Example | ||||||
| /// - with one or multiple custom certificates |  | ||||||
| /// |  | ||||||
| /// # Examples |  | ||||||
| /// | /// | ||||||
| /// ``` | /// ``` | ||||||
| /// # use std::fs::File; | /// # fn run() -> Result<(), Error> { | ||||||
| /// # use std::io::Read; | /// use std::time::Duration; | ||||||
| /// # fn build_client() -> Result<(), Box<std::error::Error>> { |  | ||||||
| /// // read a local binary DER encoded certificate |  | ||||||
| /// let mut buf = Vec::new(); |  | ||||||
| /// File::open("my-cert.der")?.read_to_end(&mut buf)?; |  | ||||||
| /// | /// | ||||||
| /// // create a certificate | /// let client = reqwest::Client::builder()? | ||||||
| /// let cert = reqwest::Certificate::from_der(&buf)?; | ///     .gzip(true) | ||||||
| /// | ///     .timeout(Duration::from_secs(10)) | ||||||
| /// // get a client builder |  | ||||||
| /// let client = reqwest::ClientBuilder::new()? |  | ||||||
| ///     .add_root_certificate(cert)? |  | ||||||
| ///     .build()?; | ///     .build()?; | ||||||
| /// # drop(client); |  | ||||||
| /// # Ok(()) |  | ||||||
| /// # } | /// # } | ||||||
| /// ``` | /// ``` | ||||||
| pub struct ClientBuilder { | pub struct ClientBuilder { | ||||||
| @@ -102,6 +90,27 @@ impl ClientBuilder { | |||||||
|     /// This can be used to connect to a server that has a self-signed |     /// This can be used to connect to a server that has a self-signed | ||||||
|     /// certificate for example. |     /// certificate for example. | ||||||
|     /// |     /// | ||||||
|  |     /// # Example | ||||||
|  |     /// ``` | ||||||
|  |     /// # use std::fs::File; | ||||||
|  |     /// # use std::io::Read; | ||||||
|  |     /// # fn build_client() -> Result<(), Box<std::error::Error>> { | ||||||
|  |     /// // read a local binary DER encoded certificate | ||||||
|  |     /// let mut buf = Vec::new(); | ||||||
|  |     /// File::open("my-cert.der")?.read_to_end(&mut buf)?; | ||||||
|  |     /// | ||||||
|  |     /// // create a certificate | ||||||
|  |     /// let cert = reqwest::Certificate::from_der(&buf)?; | ||||||
|  |     /// | ||||||
|  |     /// // get a client builder | ||||||
|  |     /// let client = reqwest::ClientBuilder::new()? | ||||||
|  |     ///     .add_root_certificate(cert)? | ||||||
|  |     ///     .build()?; | ||||||
|  |     /// # drop(client); | ||||||
|  |     /// # Ok(()) | ||||||
|  |     /// # } | ||||||
|  |     /// ``` | ||||||
|  |     /// | ||||||
|     /// # Errors |     /// # Errors | ||||||
|     /// |     /// | ||||||
|     /// This method fails if adding root certificate was unsuccessful. |     /// This method fails if adding root certificate was unsuccessful. | ||||||
| @@ -125,6 +134,8 @@ impl ClientBuilder { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Enable hostname verification. |     /// Enable hostname verification. | ||||||
|  |     /// | ||||||
|  |     /// Default is enabled. | ||||||
|     #[inline] |     #[inline] | ||||||
|     pub fn enable_hostname_verification(&mut self) -> &mut ClientBuilder { |     pub fn enable_hostname_verification(&mut self) -> &mut ClientBuilder { | ||||||
|         self.inner.enable_hostname_verification(); |         self.inner.enable_hostname_verification(); | ||||||
| @@ -166,7 +177,7 @@ impl ClientBuilder { | |||||||
|         self |         self | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Set a timeout for both the read and write operations of a client. |     /// Set a timeout for connect, read and write operations of a `Client`. | ||||||
|     #[inline] |     #[inline] | ||||||
|     pub fn timeout(&mut self, timeout: Duration) -> &mut ClientBuilder { |     pub fn timeout(&mut self, timeout: Duration) -> &mut ClientBuilder { | ||||||
|         self.timeout = Some(timeout); |         self.timeout = Some(timeout); | ||||||
|   | |||||||
| @@ -27,6 +27,8 @@ impl fmt::Debug for Response { | |||||||
| impl Response { | impl Response { | ||||||
|     /// Get the final `Url` of this `Response`. |     /// Get the final `Url` of this `Response`. | ||||||
|     /// |     /// | ||||||
|  |     /// # Example | ||||||
|  |     /// | ||||||
|     /// ```rust |     /// ```rust | ||||||
|     /// # fn run() -> Result<(), Box<::std::error::Error>> { |     /// # fn run() -> Result<(), Box<::std::error::Error>> { | ||||||
|     /// let resp = reqwest::get("http://httpbin.org/redirect/1")?; |     /// let resp = reqwest::get("http://httpbin.org/redirect/1")?; | ||||||
| @@ -41,6 +43,8 @@ impl Response { | |||||||
|  |  | ||||||
|     /// Get the `StatusCode` of this `Response`. |     /// Get the `StatusCode` of this `Response`. | ||||||
|     /// |     /// | ||||||
|  |     /// # Examples | ||||||
|  |     /// | ||||||
|     /// ```rust |     /// ```rust | ||||||
|     /// # fn run() -> Result<(), Box<::std::error::Error>> { |     /// # fn run() -> Result<(), Box<::std::error::Error>> { | ||||||
|     /// let resp = reqwest::get("http://httpbin.org/get")?; |     /// let resp = reqwest::get("http://httpbin.org/get")?; | ||||||
| @@ -80,6 +84,10 @@ impl Response { | |||||||
|  |  | ||||||
|     /// Get the `Headers` of this `Response`. |     /// Get the `Headers` of this `Response`. | ||||||
|     /// |     /// | ||||||
|  |     /// # Example | ||||||
|  |     /// | ||||||
|  |     /// Checking the `Content-Length` header before reading the response body. | ||||||
|  |     /// | ||||||
|     /// ```rust |     /// ```rust | ||||||
|     /// # use std::io::{Read, Write}; |     /// # use std::io::{Read, Write}; | ||||||
|     /// # use reqwest::Client; |     /// # use reqwest::Client; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user