adding initial support for websocket subprotocol negotation

This commit is contained in:
jmr0 2015-12-03 13:58:30 -05:00
parent 99fd946130
commit 7d0bede8ba
12 changed files with 87 additions and 49 deletions

View file

@ -37,6 +37,7 @@ use std::rc::Rc;
use std::thread;
use url::Url;
use util::mem::HeapSizeOf;
use websocket::header;
pub mod hosts;
pub mod image_cache_task;
@ -239,7 +240,7 @@ pub enum WebSocketDomAction {
#[derive(Deserialize, Serialize)]
pub enum WebSocketNetworkEvent {
ConnectionEstablished,
ConnectionEstablished(header::Headers, Vec<String>),
MessageReceived(MessageData),
Close,
}
@ -254,6 +255,7 @@ pub struct WebSocketCommunicate {
pub struct WebSocketConnectData {
pub resource_url: Url,
pub origin: String,
pub protocols: Vec<String>,
}
#[derive(Deserialize, Serialize)]
@ -429,6 +431,11 @@ pub fn load_whole_resource(resource_task: &ResourceTask, url: Url, pipeline_id:
}
}
/// Defensively unwraps the protocol string from the response object's protocol
pub fn unwrap_websocket_protocol(wsp: Option<&header::WebSocketProtocol>) -> Option<&str> {
wsp.and_then(|protocol_list| protocol_list.get(0).map(|protocol| protocol.as_ref()))
}
/// An unique identifier to keep track of each load message in the resource handler
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
pub struct ResourceId(pub u32);