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

refactor: rename header and types to field #557

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
36 changes: 18 additions & 18 deletions benches/header_map/basic.rs
Expand Up @@ -4,15 +4,15 @@ macro_rules! bench {
#[allow(unused_imports)]
use super::custom_hdr;
use fnv::FnvHasher;
use http::header::*;
use http::field::*;
use seahash::SeaHasher;
use std::hash::BuildHasherDefault;
#[allow(unused_imports)]
use test::{self, Bencher};

#[bench]
fn header_map($b: &mut Bencher) {
let $map = || HeaderMap::default();
let $map = || FieldMap::default();
$body
}

Expand Down Expand Up @@ -353,7 +353,7 @@ bench!(insert_500_custom_headers(new_map, b) {
});

bench!(insert_one_15_char_header(new_map, b) {
let hdr: HeaderName = "abcd-abcd-abcde"
let hdr: FieldName = "abcd-abcd-abcde"
.parse().unwrap();

b.iter(|| {
Expand All @@ -364,7 +364,7 @@ bench!(insert_one_15_char_header(new_map, b) {
});

bench!(insert_one_25_char_header(new_map, b) {
let hdr: HeaderName = "abcd-abcd-abcd-abcd-abcde"
let hdr: FieldName = "abcd-abcd-abcd-abcd-abcde"
.parse().unwrap();

b.iter(|| {
Expand All @@ -375,7 +375,7 @@ bench!(insert_one_25_char_header(new_map, b) {
});

bench!(insert_one_50_char_header(new_map, b) {
let hdr: HeaderName = "abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcde"
let hdr: FieldName = "abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcde"
.parse().unwrap();

b.iter(|| {
Expand All @@ -386,7 +386,7 @@ bench!(insert_one_50_char_header(new_map, b) {
});

bench!(insert_one_100_char_header(new_map, b) {
let hdr: HeaderName = "abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcdeabcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcde"
let hdr: FieldName = "abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcdeabcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcde"
.parse().unwrap();

b.iter(|| {
Expand All @@ -411,7 +411,7 @@ const HN_HDRS: [(&'static str, &'static str); 11] = [
];

bench!(hn_hdrs_set_8_get_many(new_map, b) {
let hdrs: Vec<(HeaderName, &'static str)> = super::HN_HDRS[..8].iter()
let hdrs: Vec<(FieldName, &'static str)> = super::HN_HDRS[..8].iter()
.map(|&(name, val)| (name.parse().unwrap(), val))
.collect();

Expand All @@ -430,11 +430,11 @@ bench!(hn_hdrs_set_8_get_many(new_map, b) {
});

bench!(hn_hdrs_set_8_get_miss(new_map, b) {
let hdrs: Vec<(HeaderName, &'static str)> = super::HN_HDRS[..8].iter()
let hdrs: Vec<(FieldName, &'static str)> = super::HN_HDRS[..8].iter()
.map(|&(name, val)| (name.parse().unwrap(), val))
.collect();

let miss: HeaderName = "x-wat".parse().unwrap();
let miss: FieldName = "x-wat".parse().unwrap();

b.iter(|| {
let mut h = new_map();
Expand All @@ -449,11 +449,11 @@ bench!(hn_hdrs_set_8_get_miss(new_map, b) {
});

bench!(hn_hdrs_set_11_get_with_miss(new_map, b) {
let hdrs: Vec<(HeaderName, &'static str)> = super::HN_HDRS.iter()
let hdrs: Vec<(FieldName, &'static str)> = super::HN_HDRS.iter()
.map(|&(name, val)| (name.parse().unwrap(), val))
.collect();

let miss: HeaderName = "x-wat".parse().unwrap();
let miss: FieldName = "x-wat".parse().unwrap();

b.iter(|| {
let mut h = new_map();
Expand All @@ -470,9 +470,9 @@ bench!(hn_hdrs_set_11_get_with_miss(new_map, b) {
});
});

use http::header::*;
use http::field::*;

fn custom_hdr(n: usize) -> Vec<HeaderName> {
fn custom_hdr(n: usize) -> Vec<FieldName> {
(0..n)
.map(|i| {
let s = format!("x-custom-{}", i);
Expand All @@ -481,7 +481,7 @@ fn custom_hdr(n: usize) -> Vec<HeaderName> {
.collect()
}

fn med_custom_hdr(n: usize) -> Vec<HeaderName> {
fn med_custom_hdr(n: usize) -> Vec<FieldName> {
(0..n)
.map(|i| {
let s = format!("content-length-{}", i);
Expand All @@ -490,7 +490,7 @@ fn med_custom_hdr(n: usize) -> Vec<HeaderName> {
.collect()
}

fn long_custom_hdr(n: usize) -> Vec<HeaderName> {
fn long_custom_hdr(n: usize) -> Vec<FieldName> {
(0..n)
.map(|i| {
let s = format!("access-control-allow-headers-{}", i);
Expand All @@ -499,7 +499,7 @@ fn long_custom_hdr(n: usize) -> Vec<HeaderName> {
.collect()
}

fn very_long_custom_hdr(n: usize) -> Vec<HeaderName> {
fn very_long_custom_hdr(n: usize) -> Vec<FieldName> {
(0..n)
.map(|i| {
let s = format!("access-control-allow-access-control-allow-headers-{}", i);
Expand All @@ -508,7 +508,7 @@ fn very_long_custom_hdr(n: usize) -> Vec<HeaderName> {
.collect()
}

fn custom_std(n: usize) -> Vec<HeaderName> {
fn custom_std(n: usize) -> Vec<FieldName> {
(0..n)
.map(|i| {
let s = format!("{}-{}", STD[i % STD.len()].as_str(), i);
Expand All @@ -517,7 +517,7 @@ fn custom_std(n: usize) -> Vec<HeaderName> {
.collect()
}

const STD: &'static [HeaderName] = &[
const STD: &'static [FieldName] = &[
ACCEPT,
ACCEPT_CHARSET,
ACCEPT_ENCODING,
Expand Down
12 changes: 6 additions & 6 deletions benches/header_name.rs
Expand Up @@ -4,7 +4,7 @@ extern crate bytes;
extern crate http;
extern crate test;

use http::header::HeaderName;
use http::field::FieldName;
use test::Bencher;

fn make_all_known_headers() -> Vec<Vec<u8>> {
Expand Down Expand Up @@ -256,23 +256,23 @@ static ALL_KNOWN_HEADERS: &[&str] = &[
fn header_name_easy(b: &mut Bencher) {
let name = b"Content-type";
b.iter(|| {
HeaderName::from_bytes(&name[..]).unwrap();
FieldName::from_bytes(&name[..]).unwrap();
});
}

#[bench]
fn header_name_custom(b: &mut Bencher) {
let name = b"Foo-Bar-Baz-Blah";
b.iter(|| {
HeaderName::from_bytes(&name[..]).unwrap();
FieldName::from_bytes(&name[..]).unwrap();
});
}

#[bench]
fn header_name_bad(b: &mut Bencher) {
let name = b"bad header name";
b.iter(|| {
HeaderName::from_bytes(&name[..]).expect_err("Bad header name");
FieldName::from_bytes(&name[..]).expect_err("Bad header name");
});
}

Expand All @@ -281,7 +281,7 @@ fn header_name_various(b: &mut Bencher) {
let all_known_headers = make_all_known_headers();
b.iter(|| {
for name in &all_known_headers{
HeaderName::from_bytes(name.as_slice()).unwrap();
FieldName::from_bytes(name.as_slice()).unwrap();
}
});
}
Expand All @@ -290,7 +290,7 @@ fn header_name_various(b: &mut Bencher) {
fn header_name_from_static(b: &mut Bencher) {
b.iter(|| {
for name in ALL_KNOWN_HEADERS {
HeaderName::from_static(name);
FieldName::from_static(name);
}
});
}
4 changes: 2 additions & 2 deletions benches/header_name2.rs
@@ -1,5 +1,5 @@
use criterion::{criterion_group, criterion_main, BenchmarkId,Criterion, Throughput};
use http::header::HeaderName;
use http::field::FieldName;

// This is a list of some of the standard headers ordered by increasing size.
// It has exactly one standard header per size (some sizes don't have a standard
Expand Down Expand Up @@ -42,7 +42,7 @@ fn header_name_by_size(c: &mut Criterion) {
for name in STANDARD_HEADERS_BY_SIZE {
group.throughput(Throughput::Bytes(name.len() as u64));
group.bench_with_input(BenchmarkId::from_parameter(name), name, |b, name| {
b.iter(|| HeaderName::from_static(name) );
b.iter(|| FieldName::from_static(name) );
});
}
group.finish();
Expand Down
10 changes: 5 additions & 5 deletions benches/header_value.rs
Expand Up @@ -3,7 +3,7 @@
extern crate test;

use bytes::Bytes;
use http::HeaderValue;
use http::FieldValue;
use test::Bencher;

static SHORT: &'static [u8] = b"localhost";
Expand All @@ -14,7 +14,7 @@ fn from_shared_short(b: &mut Bencher) {
b.bytes = SHORT.len() as u64;
let bytes = Bytes::from_static(SHORT);
b.iter(|| {
HeaderValue::from_maybe_shared(bytes.clone()).unwrap();
FieldValue::from_maybe_shared(bytes.clone()).unwrap();
});
}

Expand All @@ -23,7 +23,7 @@ fn from_shared_long(b: &mut Bencher) {
b.bytes = LONG.len() as u64;
let bytes = Bytes::from_static(LONG);
b.iter(|| {
HeaderValue::from_maybe_shared(bytes.clone()).unwrap();
FieldValue::from_maybe_shared(bytes.clone()).unwrap();
});
}

Expand All @@ -32,7 +32,7 @@ fn from_shared_unchecked_short(b: &mut Bencher) {
b.bytes = SHORT.len() as u64;
let bytes = Bytes::from_static(SHORT);
b.iter(|| unsafe {
HeaderValue::from_maybe_shared_unchecked(bytes.clone());
FieldValue::from_maybe_shared_unchecked(bytes.clone());
});
}

Expand All @@ -41,6 +41,6 @@ fn from_shared_unchecked_long(b: &mut Bencher) {
b.bytes = LONG.len() as u64;
let bytes = Bytes::from_static(LONG);
b.iter(|| unsafe {
HeaderValue::from_maybe_shared_unchecked(bytes.clone());
FieldValue::from_maybe_shared_unchecked(bytes.clone());
});
}
26 changes: 13 additions & 13 deletions src/error.rs
Expand Up @@ -2,7 +2,7 @@ use std::error;
use std::fmt;
use std::result;

use crate::header;
use crate::field;
use crate::method;
use crate::status;
use crate::uri;
Expand All @@ -25,8 +25,8 @@ enum ErrorKind {
Method(method::InvalidMethod),
Uri(uri::InvalidUri),
UriParts(uri::InvalidUriParts),
HeaderName(header::InvalidHeaderName),
HeaderValue(header::InvalidHeaderValue),
FieldName(field::InvalidFieldName),
FieldValue(field::InvalidFieldValue),
}

impl fmt::Debug for Error {
Expand Down Expand Up @@ -59,8 +59,8 @@ impl Error {
Method(ref e) => e,
Uri(ref e) => e,
UriParts(ref e) => e,
HeaderName(ref e) => e,
HeaderValue(ref e) => e,
FieldName(ref e) => e,
FieldValue(ref e) => e,
}
}
}
Expand Down Expand Up @@ -105,18 +105,18 @@ impl From<uri::InvalidUriParts> for Error {
}
}

impl From<header::InvalidHeaderName> for Error {
fn from(err: header::InvalidHeaderName) -> Error {
impl From<field::InvalidFieldName> for Error {
fn from(err: field::InvalidFieldName) -> Error {
Error {
inner: ErrorKind::HeaderName(err),
inner: ErrorKind::FieldName(err),
}
}
}

impl From<header::InvalidHeaderValue> for Error {
fn from(err: header::InvalidHeaderValue) -> Error {
impl From<field::InvalidFieldValue> for Error {
fn from(err: field::InvalidFieldValue) -> Error {
Error {
inner: ErrorKind::HeaderValue(err),
inner: ErrorKind::FieldValue(err),
}
}
}
Expand All @@ -136,11 +136,11 @@ mod tests {
if let Err(e) = status::StatusCode::from_u16(6666) {
let err: Error = e.into();
let ie = err.get_ref();
assert!(!ie.is::<header::InvalidHeaderValue>());
assert!(!ie.is::<field::InvalidFieldValue>());
assert!(ie.is::<status::InvalidStatusCode>());
ie.downcast_ref::<status::InvalidStatusCode>().unwrap();

assert!(!err.is::<header::InvalidHeaderValue>());
assert!(!err.is::<field::InvalidFieldValue>());
assert!(err.is::<status::InvalidStatusCode>());
} else {
panic!("Bad status allowed!");
Expand Down