Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method_ref, uri_ref, headers_ref to request::Builder #284

Merged
merged 3 commits into from Dec 19, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/request.rs
Expand Up @@ -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.get_method(),Some(Method::GET));
/// req.method("POST");
/// assert_eq!(req.get_method(),Some(Method::POST));
/// req.method("DELETE");
/// assert_eq!(req.get_method(),Some(Method::DELETE));
/// ```
pub fn get_method(&self) -> Option<Method>
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
{
if self.err.is_some() {
return None
}
match &self.head {
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
&Some(ref head) => Some(head.method.clone()),
&None => None
}
}

/// Set the URI for this request.
///
/// This function will configure the URI of the `Request` that will
Expand Down Expand Up @@ -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.get_uri().unwrap().to_string(), "/" );
/// req.uri("https://www.rust-lang.org/");
/// assert_eq!(req.get_uri().unwrap().to_string(), "https://www.rust-lang.org/" );
/// ```
pub fn get_uri(&self) -> Option<Uri>
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
{
if self.err.is_some() {
return None;
}
match &self.head
{
&Some(ref head) => Some(head.uri.clone()),
&None => None
}
}

/// Set the HTTP version for this request.
///
/// This function will configure the HTTP version of the `Request` that
Expand Down Expand Up @@ -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.get_headers().unwrap();
/// assert_eq!( headers["Accept"], "text/html" );
/// assert_eq!( headers["X-Custom-Foo"], "bar" );
/// ```
pub fn get_headers(&self ) -> Option<HeaderMap<HeaderValue>> {
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
if self.err.is_some() {
return None;
}
match &self.head
{
&Some(ref head) => Some(head.headers.clone()),
&None => None
}
}

/// Adds an extension to this builder
///
/// # Examples
Expand Down