perf(client): don't make a copy of Headers each Request
This commit is contained in:
@@ -14,7 +14,7 @@ use http;
|
||||
use tokio::reactor::Handle;
|
||||
pub use tokio_service::Service;
|
||||
|
||||
use header::{Headers, Host};
|
||||
use header::{Host};
|
||||
use proto;
|
||||
use proto::request;
|
||||
use method::Method;
|
||||
@@ -180,12 +180,14 @@ where C: Connect,
|
||||
))));
|
||||
}
|
||||
};
|
||||
let host = Host::new(domain.host().expect("authority implies host").to_owned(), domain.port());
|
||||
let (mut head, body) = request::split(req);
|
||||
let mut headers = Headers::new();
|
||||
headers.set(host);
|
||||
headers.extend(head.headers.iter());
|
||||
head.headers = headers;
|
||||
if !head.headers.has::<Host>() {
|
||||
let host = Host::new(
|
||||
domain.host().expect("authority implies host").to_owned(),
|
||||
domain.port(),
|
||||
);
|
||||
head.headers.set_pos(0, host);
|
||||
}
|
||||
|
||||
use futures::Sink;
|
||||
use futures::sync::{mpsc, oneshot};
|
||||
|
||||
@@ -23,6 +23,11 @@ impl<K: PartialEq, V> VecMap<K, V> {
|
||||
self.vec.push((key, value));
|
||||
}
|
||||
|
||||
pub fn insert_pos(&mut self, key: K, value: V, pos: usize) {
|
||||
debug_assert!(!self.contains_key(&key));
|
||||
self.vec.insert(pos, (key, value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn append(&mut self, key: K, value: V) {
|
||||
self.vec.push((key, value));
|
||||
|
||||
@@ -392,6 +392,14 @@ impl Headers {
|
||||
Item::new_typed(value));
|
||||
}
|
||||
|
||||
pub(crate) fn set_pos<H: Header>(&mut self, pos: usize, value: H) {
|
||||
self.data.insert_pos(
|
||||
HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>()))),
|
||||
Item::new_typed(value),
|
||||
pos,
|
||||
);
|
||||
}
|
||||
|
||||
/// Get a reference to the header field's value, if it exists.
|
||||
pub fn get<H: Header>(&self) -> Option<&H> {
|
||||
self.data.get(&HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>()))))
|
||||
|
||||
Reference in New Issue
Block a user