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.
This commit is contained in:
committed by
GitHub
parent
213d64086c
commit
6a7b064f2a
@@ -29,37 +29,16 @@ impl Header {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The header name.
|
/// The header name.
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// let header = "X-Forwarded-For: 127.0.0.1"
|
|
||||||
/// .parse::<ureq::Header>()
|
|
||||||
/// .unwrap();
|
|
||||||
/// assert_eq!("X-Forwarded-For", header.name());
|
|
||||||
/// ```
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&self.line.as_str()[0..self.index]
|
&self.line.as_str()[0..self.index]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The header value.
|
/// The header value.
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// let header = "X-Forwarded-For: 127.0.0.1"
|
|
||||||
/// .parse::<ureq::Header>()
|
|
||||||
/// .unwrap();
|
|
||||||
/// assert_eq!("127.0.0.1", header.value());
|
|
||||||
/// ```
|
|
||||||
pub fn value(&self) -> &str {
|
pub fn value(&self) -> &str {
|
||||||
&self.line.as_str()[self.index + 1..].trim()
|
&self.line.as_str()[self.index + 1..].trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compares the given str to the header name ignoring case.
|
/// Compares the given str to the header name ignoring case.
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// let header = "X-Forwarded-For: 127.0.0.1"
|
|
||||||
/// .parse::<ureq::Header>()
|
|
||||||
/// .unwrap();
|
|
||||||
/// assert!(header.is_name("x-forwarded-for"));
|
|
||||||
/// ```
|
|
||||||
pub fn is_name(&self, other: &str) -> bool {
|
pub fn is_name(&self, other: &str) -> bool {
|
||||||
self.name().eq_ignore_ascii_case(other)
|
self.name().eq_ignore_ascii_case(other)
|
||||||
}
|
}
|
||||||
@@ -225,3 +204,13 @@ fn value_with_whitespace() {
|
|||||||
let h = "foo: bar ".parse::<Header>().unwrap();
|
let h = "foo: bar ".parse::<Header>().unwrap();
|
||||||
assert_eq!(h.value(), "bar");
|
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"));
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,16 +7,14 @@ use url::Url;
|
|||||||
#[cfg(feature = "cookies")]
|
#[cfg(feature = "cookies")]
|
||||||
use cookie::Cookie;
|
use cookie::Cookie;
|
||||||
|
|
||||||
|
use crate::body::{self, BodySize, Payload, SizedReader};
|
||||||
use crate::error::{Error, ErrorKind};
|
use crate::error::{Error, ErrorKind};
|
||||||
use crate::header;
|
use crate::header;
|
||||||
|
use crate::header::{get_header, Header};
|
||||||
use crate::resolve::ArcResolver;
|
use crate::resolve::ArcResolver;
|
||||||
|
use crate::response::Response;
|
||||||
use crate::stream::{self, connect_test, Stream};
|
use crate::stream::{self, connect_test, Stream};
|
||||||
use crate::Agent;
|
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.
|
/// A Unit is fully-built Request, ready to execute.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user