From 6a7b064f2a838450e787fd8cdc15fb98f36dbae5 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 22 Nov 2020 00:15:13 -0800 Subject: [PATCH] Remove Headers from the public API. (#224) It turns out Headers is actually an internal-only API. None of the user-facing types use it. Unfortunately, making it unexported also required deleting the doctests, since doctests can only run against a public interface. --- src/header.rs | 31 ++++++++++--------------------- src/unit.rs | 8 +++----- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/header.rs b/src/header.rs index 5fb5675..038a0b0 100644 --- a/src/header.rs +++ b/src/header.rs @@ -29,37 +29,16 @@ impl Header { } /// The header name. - /// - /// ``` - /// let header = "X-Forwarded-For: 127.0.0.1" - /// .parse::() - /// .unwrap(); - /// assert_eq!("X-Forwarded-For", header.name()); - /// ``` pub fn name(&self) -> &str { &self.line.as_str()[0..self.index] } /// The header value. - /// - /// ``` - /// let header = "X-Forwarded-For: 127.0.0.1" - /// .parse::() - /// .unwrap(); - /// assert_eq!("127.0.0.1", header.value()); - /// ``` pub fn value(&self) -> &str { &self.line.as_str()[self.index + 1..].trim() } /// Compares the given str to the header name ignoring case. - /// - /// ``` - /// let header = "X-Forwarded-For: 127.0.0.1" - /// .parse::() - /// .unwrap(); - /// assert!(header.is_name("x-forwarded-for")); - /// ``` pub fn is_name(&self, other: &str) -> bool { self.name().eq_ignore_ascii_case(other) } @@ -225,3 +204,13 @@ fn value_with_whitespace() { let h = "foo: bar ".parse::
().unwrap(); assert_eq!(h.value(), "bar"); } + +#[test] +fn name_and_value() { + let header: Header = "X-Forwarded-For: 127.0.0.1".parse().unwrap(); + assert_eq!("X-Forwarded-For", header.name()); + assert_eq!("127.0.0.1", header.value()); + assert!(header.is_name("X-Forwarded-For")); + assert!(header.is_name("x-forwarded-for")); + assert!(header.is_name("X-FORWARDED-FOR")); +} diff --git a/src/unit.rs b/src/unit.rs index 51784d6..166fc12 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -7,16 +7,14 @@ use url::Url; #[cfg(feature = "cookies")] use cookie::Cookie; +use crate::body::{self, BodySize, Payload, SizedReader}; use crate::error::{Error, ErrorKind}; use crate::header; +use crate::header::{get_header, Header}; use crate::resolve::ArcResolver; +use crate::response::Response; use crate::stream::{self, connect_test, Stream}; use crate::Agent; -use crate::{ - body::{self, BodySize, Payload, SizedReader}, - header::get_header, -}; -use crate::{Header, Response}; /// A Unit is fully-built Request, ready to execute. ///