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; | use tokio::reactor::Handle; | ||||||
| pub use tokio_service::Service; | pub use tokio_service::Service; | ||||||
|  |  | ||||||
| use header::{Headers, Host}; | use header::{Host}; | ||||||
| use proto; | use proto; | ||||||
| use proto::request; | use proto::request; | ||||||
| use method::Method; | 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 head, body) = request::split(req); | ||||||
|         let mut headers = Headers::new(); |         if !head.headers.has::<Host>() { | ||||||
|         headers.set(host); |             let host = Host::new( | ||||||
|         headers.extend(head.headers.iter()); |                 domain.host().expect("authority implies host").to_owned(), | ||||||
|         head.headers = headers; |                 domain.port(), | ||||||
|  |             ); | ||||||
|  |             head.headers.set_pos(0, host); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         use futures::Sink; |         use futures::Sink; | ||||||
|         use futures::sync::{mpsc, oneshot}; |         use futures::sync::{mpsc, oneshot}; | ||||||
|   | |||||||
| @@ -23,6 +23,11 @@ impl<K: PartialEq, V> VecMap<K, V> { | |||||||
|         self.vec.push((key, value)); |         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] |     #[inline] | ||||||
|     pub fn append(&mut self, key: K, value: V) { |     pub fn append(&mut self, key: K, value: V) { | ||||||
|         self.vec.push((key, value)); |         self.vec.push((key, value)); | ||||||
|   | |||||||
| @@ -392,6 +392,14 @@ impl Headers { | |||||||
|                          Item::new_typed(value)); |                          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. |     /// Get a reference to the header field's value, if it exists. | ||||||
|     pub fn get<H: Header>(&self) -> Option<&H> { |     pub fn get<H: Header>(&self) -> Option<&H> { | ||||||
|         self.data.get(&HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>())))) |         self.data.get(&HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>())))) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user