mirror of
https://github.com/actix/actix-web.git
synced 2024-12-30 12:00:38 +00:00
proper connection upgrade check
This commit is contained in:
parent
f26d4b6a23
commit
3301a46264
2 changed files with 11 additions and 3 deletions
|
@ -3,7 +3,7 @@ use std::collections::VecDeque;
|
|||
use std::rc::Rc;
|
||||
|
||||
use crate::extensions::Extensions;
|
||||
use crate::http::{HeaderMap, Method, StatusCode, Uri, Version};
|
||||
use crate::http::{header, HeaderMap, Method, StatusCode, Uri, Version};
|
||||
|
||||
/// Represents various types of connection
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
|
@ -33,7 +33,15 @@ pub trait Head: Default + 'static {
|
|||
fn set_connection_type(&mut self, ctype: ConnectionType);
|
||||
|
||||
fn upgrade(&self) -> bool {
|
||||
self.connection_type() == ConnectionType::Upgrade
|
||||
if let Some(hdr) = self.headers().get(header::CONNECTION) {
|
||||
if let Ok(s) = hdr.to_str() {
|
||||
s.to_ascii_lowercase().contains("upgrade")
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if keep-alive is enabled
|
||||
|
|
|
@ -132,7 +132,7 @@ pub fn verify_handshake(req: &Request) -> Result<(), HandshakeError> {
|
|||
// Check for "UPGRADE" to websocket header
|
||||
let has_hdr = if let Some(hdr) = req.headers().get(header::UPGRADE) {
|
||||
if let Ok(s) = hdr.to_str() {
|
||||
s.to_lowercase().contains("websocket")
|
||||
s.to_ascii_lowercase().contains("websocket")
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue