Skip to content

Commit

Permalink
list all header names in request and response
Browse files Browse the repository at this point in the history
  • Loading branch information
algesten committed Feb 3, 2019
1 parent 4c9da1d commit 141668a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ impl Request {
get_header(&self.headers, name)
}

/// A list of the set header names in this request. Lowercased to be uniform.
///
/// ```
/// let req = ureq::get("/my_page")
/// .set("X-API-Key", "foobar")
/// .set("Content-Type", "application/json")
/// .build();
/// assert_eq!(req.header_names(), vec!["x-api-key", "content-type"]);
/// ```
pub fn header_names(&self) -> Vec<String> {
self.headers
.iter()
.map(|h| h.name().to_ascii_lowercase())
.collect()
}

/// Tells if the header has been set.
///
/// ```
Expand Down
9 changes: 9 additions & 0 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ impl Response {
.map(|h| h.value())
}

/// A list of the header names in this response.
/// Lowercased to be uniform.
pub fn headers_names(&self) -> Vec<String> {
self.headers
.iter()
.map(|h| h.name().to_ascii_lowercase())
.collect()
}

/// Tells if the response has the named header.
pub fn has<'a>(&self, name: &'a str) -> bool {
self.header(name).is_some()
Expand Down

0 comments on commit 141668a

Please sign in to comment.