mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-24 22:37:35 +02:00
use custom headers map; more optimizations
This commit is contained in:
@ -104,7 +104,7 @@ impl Client {
|
||||
{
|
||||
let mut req = ClientRequest::new(method, url, self.0.clone());
|
||||
|
||||
for (key, value) in &self.0.headers {
|
||||
for (key, value) in self.0.headers.iter() {
|
||||
req = req.set_header_if_none(key.clone(), value.clone());
|
||||
}
|
||||
req
|
||||
@ -119,7 +119,7 @@ impl Client {
|
||||
Uri: HttpTryFrom<U>,
|
||||
{
|
||||
let mut req = self.request(head.method.clone(), url);
|
||||
for (key, value) in &head.headers {
|
||||
for (key, value) in head.headers.iter() {
|
||||
req = req.set_header_if_none(key.clone(), value.clone());
|
||||
}
|
||||
req
|
||||
@ -187,7 +187,7 @@ impl Client {
|
||||
Uri: HttpTryFrom<U>,
|
||||
{
|
||||
let mut req = ws::WebsocketsRequest::new(url, self.0.clone());
|
||||
for (key, value) in &self.0.headers {
|
||||
for (key, value) in self.0.headers.iter() {
|
||||
req.head.headers.insert(key.clone(), value.clone());
|
||||
}
|
||||
req
|
||||
|
@ -396,7 +396,7 @@ impl ClientRequest {
|
||||
if self.default_headers {
|
||||
// set request host header
|
||||
if let Some(host) = self.head.uri.host() {
|
||||
if !self.head.headers.contains_key(header::HOST) {
|
||||
if !self.head.headers.contains_key(&header::HOST) {
|
||||
let mut wrt = BytesMut::with_capacity(host.len() + 5).writer();
|
||||
|
||||
let _ = match self.head.uri.port_u16() {
|
||||
@ -414,7 +414,7 @@ impl ClientRequest {
|
||||
}
|
||||
|
||||
// user agent
|
||||
if !self.head.headers.contains_key(header::USER_AGENT) {
|
||||
if !self.head.headers.contains_key(&header::USER_AGENT) {
|
||||
self.head.headers.insert(
|
||||
header::USER_AGENT,
|
||||
HeaderValue::from_static(concat!("awc/", env!("CARGO_PKG_VERSION"))),
|
||||
|
@ -46,7 +46,7 @@ impl<S> HttpMessage for ClientResponse<S> {
|
||||
|
||||
if self.extensions().get::<Cookies>().is_none() {
|
||||
let mut cookies = Vec::new();
|
||||
for hdr in self.headers().get_all(SET_COOKIE) {
|
||||
for hdr in self.headers().get_all(&SET_COOKIE) {
|
||||
let s = std::str::from_utf8(hdr.as_bytes())
|
||||
.map_err(CookieParseError::from)?;
|
||||
cookies.push(Cookie::parse_encoded(s)?.into_owned());
|
||||
@ -160,7 +160,7 @@ where
|
||||
/// Create `MessageBody` for request.
|
||||
pub fn new(res: &mut ClientResponse<S>) -> MessageBody<S> {
|
||||
let mut len = None;
|
||||
if let Some(l) = res.headers().get(CONTENT_LENGTH) {
|
||||
if let Some(l) = res.headers().get(&CONTENT_LENGTH) {
|
||||
if let Ok(s) = l.to_str() {
|
||||
if let Ok(l) = s.parse::<usize>() {
|
||||
len = Some(l)
|
||||
@ -254,7 +254,7 @@ where
|
||||
}
|
||||
|
||||
let mut len = None;
|
||||
if let Some(l) = req.headers().get(CONTENT_LENGTH) {
|
||||
if let Some(l) = req.headers().get(&CONTENT_LENGTH) {
|
||||
if let Ok(s) = l.to_str() {
|
||||
if let Ok(l) = s.parse::<usize>() {
|
||||
len = Some(l)
|
||||
|
@ -236,7 +236,7 @@ impl WebsocketsRequest {
|
||||
let mut slf = if self.default_headers {
|
||||
// set request host header
|
||||
if let Some(host) = self.head.uri.host() {
|
||||
if !self.head.headers.contains_key(header::HOST) {
|
||||
if !self.head.headers.contains_key(&header::HOST) {
|
||||
let mut wrt = BytesMut::with_capacity(host.len() + 5).writer();
|
||||
|
||||
let _ = match self.head.uri.port_u16() {
|
||||
@ -324,7 +324,7 @@ impl WebsocketsRequest {
|
||||
return Err(WsClientError::InvalidResponseStatus(head.status));
|
||||
}
|
||||
// Check for "UPGRADE" to websocket header
|
||||
let has_hdr = if let Some(hdr) = head.headers.get(header::UPGRADE) {
|
||||
let has_hdr = if let Some(hdr) = head.headers.get(&header::UPGRADE) {
|
||||
if let Ok(s) = hdr.to_str() {
|
||||
s.to_ascii_lowercase().contains("websocket")
|
||||
} else {
|
||||
@ -338,7 +338,7 @@ impl WebsocketsRequest {
|
||||
return Err(WsClientError::InvalidUpgradeHeader);
|
||||
}
|
||||
// Check for "CONNECTION" header
|
||||
if let Some(conn) = head.headers.get(header::CONNECTION) {
|
||||
if let Some(conn) = head.headers.get(&header::CONNECTION) {
|
||||
if let Ok(s) = conn.to_str() {
|
||||
if !s.to_ascii_lowercase().contains("upgrade") {
|
||||
log::trace!("Invalid connection header: {}", s);
|
||||
@ -355,7 +355,7 @@ impl WebsocketsRequest {
|
||||
return Err(WsClientError::MissingConnectionHeader);
|
||||
}
|
||||
|
||||
if let Some(hdr_key) = head.headers.get(header::SEC_WEBSOCKET_ACCEPT) {
|
||||
if let Some(hdr_key) = head.headers.get(&header::SEC_WEBSOCKET_ACCEPT) {
|
||||
let encoded = ws::hash_key(key.as_ref());
|
||||
if hdr_key.as_bytes() != encoded.as_bytes() {
|
||||
log::trace!(
|
||||
|
Reference in New Issue
Block a user