diff --git a/src/request.rs b/src/request.rs index 382af1e4..2fc1163d 100644 --- a/src/request.rs +++ b/src/request.rs @@ -771,6 +771,34 @@ impl Builder { self } + /// Get the HTTP Method for this request. + /// + /// By default this is `GET`. + /// if builder has error, returns None. + /// + /// # Examples + /// + /// ``` + /// # use http::*; + /// + /// let mut req = Request::builder(); + /// assert_eq!(req.method_ref(),Some(&Method::GET)); + /// req.method("POST"); + /// assert_eq!(req.method_ref(),Some(&Method::POST)); + /// req.method("DELETE"); + /// assert_eq!(req.method_ref(),Some(&Method::DELETE)); + /// ``` + pub fn method_ref(&self) -> Option<&Method> + { + if self.err.is_some() { + return None + } + match self.head { + Some(ref head) => Some(&head.method), + None => None + } + } + /// Set the URI for this request. /// /// This function will configure the URI of the `Request` that will @@ -800,6 +828,31 @@ impl Builder { self } + /// Get the URI for this request + /// + /// By default this is `/` + /// # Examples + /// + /// ``` + /// # use http::*; + /// + /// let mut req = Request::builder(); + /// assert_eq!(req.uri_ref().unwrap().to_string(), "/" ); + /// req.uri("https://www.rust-lang.org/"); + /// assert_eq!(req.uri_ref().unwrap().to_string(), "https://www.rust-lang.org/" ); + /// ``` + pub fn uri_ref(&self) -> Option<&Uri> + { + if self.err.is_some() { + return None; + } + match self.head + { + Some(ref head) => Some(&head.uri), + None => None + } + } + /// Set the HTTP version for this request. /// /// This function will configure the HTTP version of the `Request` that @@ -860,6 +913,33 @@ impl Builder { self } + /// Get header on this request builder. + /// when builder has error returns None + /// + /// # Example + /// + /// ``` + /// # use http::*; + /// # use http::header::HeaderValue; + /// # use http::request::Builder; + /// let mut req = Request::builder(); + /// req.header("Accept", "text/html") + /// .header("X-Custom-Foo", "bar"); + /// let headers = req.headers_ref().unwrap(); + /// assert_eq!( headers["Accept"], "text/html" ); + /// assert_eq!( headers["X-Custom-Foo"], "bar" ); + /// ``` + pub fn headers_ref(&self) -> Option<&HeaderMap> { + if self.err.is_some() { + return None; + } + match self.head + { + Some(ref head) => Some(&head.headers), + None => None + } + } + /// Adds an extension to this builder /// /// # Examples