mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Add support for websocket request and response cookies
Also change expected behavior to pass for all in tests/wpt/web-platform-tests/websockets/cookies
This commit is contained in:
parent
7c249b1d53
commit
cf6fd6dafe
9 changed files with 23 additions and 32 deletions
|
@ -349,7 +349,7 @@ fn set_default_accept(headers: &mut Headers) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_request_cookies(url: Url, headers: &mut Headers, cookie_jar: &Arc<RwLock<CookieStorage>>) {
|
pub fn set_request_cookies(url: Url, headers: &mut Headers, cookie_jar: &Arc<RwLock<CookieStorage>>) {
|
||||||
let mut cookie_jar = cookie_jar.write().unwrap();
|
let mut cookie_jar = cookie_jar.write().unwrap();
|
||||||
if let Some(cookie_list) = cookie_jar.cookies_for_url(&url, CookieSource::HTTP) {
|
if let Some(cookie_list) = cookie_jar.cookies_for_url(&url, CookieSource::HTTP) {
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
|
|
|
@ -362,6 +362,6 @@ impl ResourceManager {
|
||||||
fn websocket_connect(&self,
|
fn websocket_connect(&self,
|
||||||
connect: WebSocketCommunicate,
|
connect: WebSocketCommunicate,
|
||||||
connect_data: WebSocketConnectData) {
|
connect_data: WebSocketConnectData) {
|
||||||
websocket_loader::init(connect, connect_data);
|
websocket_loader::init(connect, connect_data, self.cookie_storage.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use cookie_storage::CookieStorage;
|
||||||
|
use http_loader;
|
||||||
use hyper::header::Host;
|
use hyper::header::Host;
|
||||||
use net_traits::MessageData;
|
use net_traits::MessageData;
|
||||||
use net_traits::hosts::replace_hosts;
|
use net_traits::hosts::replace_hosts;
|
||||||
use net_traits::unwrap_websocket_protocol;
|
use net_traits::unwrap_websocket_protocol;
|
||||||
use net_traits::{WebSocketCommunicate, WebSocketConnectData, WebSocketDomAction, WebSocketNetworkEvent};
|
use net_traits::{WebSocketCommunicate, WebSocketConnectData, WebSocketDomAction, WebSocketNetworkEvent};
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use util::thread::spawn_named;
|
use util::thread::spawn_named;
|
||||||
use websocket::client::receiver::Receiver;
|
use websocket::client::receiver::Receiver;
|
||||||
|
@ -25,7 +27,8 @@ use websocket::{Client, Message};
|
||||||
|
|
||||||
/// *Establish a WebSocket Connection* as defined in RFC 6455.
|
/// *Establish a WebSocket Connection* as defined in RFC 6455.
|
||||||
fn establish_a_websocket_connection(resource_url: &Url, net_url: (Host, String, bool),
|
fn establish_a_websocket_connection(resource_url: &Url, net_url: (Host, String, bool),
|
||||||
origin: String, protocols: Vec<String>)
|
origin: String, protocols: Vec<String>,
|
||||||
|
cookie_jar: Arc<RwLock<CookieStorage>>)
|
||||||
-> WebSocketResult<(Headers, Sender<WebSocketStream>, Receiver<WebSocketStream>)> {
|
-> WebSocketResult<(Headers, Sender<WebSocketStream>, Receiver<WebSocketStream>)> {
|
||||||
|
|
||||||
let host = Host {
|
let host = Host {
|
||||||
|
@ -40,6 +43,8 @@ fn establish_a_websocket_connection(resource_url: &Url, net_url: (Host, String,
|
||||||
request.headers.set(WebSocketProtocol(protocols.clone()));
|
request.headers.set(WebSocketProtocol(protocols.clone()));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
http_loader::set_request_cookies(resource_url.clone(), &mut request.headers, &cookie_jar);
|
||||||
|
|
||||||
let response = try!(request.send());
|
let response = try!(request.send());
|
||||||
try!(response.validate());
|
try!(response.validate());
|
||||||
|
|
||||||
|
@ -58,7 +63,7 @@ fn establish_a_websocket_connection(resource_url: &Url, net_url: (Host, String,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(connect: WebSocketCommunicate, connect_data: WebSocketConnectData) {
|
pub fn init(connect: WebSocketCommunicate, connect_data: WebSocketConnectData, cookie_jar: Arc<RwLock<CookieStorage>>) {
|
||||||
spawn_named(format!("WebSocket connection to {}", connect_data.resource_url), move || {
|
spawn_named(format!("WebSocket connection to {}", connect_data.resource_url), move || {
|
||||||
// Step 8: Protocols.
|
// Step 8: Protocols.
|
||||||
|
|
||||||
|
@ -78,7 +83,8 @@ pub fn init(connect: WebSocketCommunicate, connect_data: WebSocketConnectData) {
|
||||||
let channel = establish_a_websocket_connection(&connect_data.resource_url,
|
let channel = establish_a_websocket_connection(&connect_data.resource_url,
|
||||||
net_url,
|
net_url,
|
||||||
connect_data.origin,
|
connect_data.origin,
|
||||||
connect_data.protocols.clone());
|
connect_data.protocols.clone(),
|
||||||
|
cookie_jar);
|
||||||
let (_, ws_sender, mut receiver) = match channel {
|
let (_, ws_sender, mut receiver) = match channel {
|
||||||
Ok(channel) => {
|
Ok(channel) => {
|
||||||
let _ = connect.event_sender.send(WebSocketNetworkEvent::ConnectionEstablished(channel.0.clone(),
|
let _ = connect.event_sender.send(WebSocketNetworkEvent::ConnectionEstablished(channel.0.clone(),
|
||||||
|
|
|
@ -29,7 +29,8 @@ use js::jsapi::{JSAutoCompartment, JSAutoRequest, RootedValue};
|
||||||
use js::jsapi::{JS_GetArrayBufferData, JS_NewArrayBuffer};
|
use js::jsapi::{JS_GetArrayBufferData, JS_NewArrayBuffer};
|
||||||
use js::jsval::UndefinedValue;
|
use js::jsval::UndefinedValue;
|
||||||
use libc::{uint32_t, uint8_t};
|
use libc::{uint32_t, uint8_t};
|
||||||
use net_traits::ControlMsg::WebsocketConnect;
|
use net_traits::ControlMsg::{WebsocketConnect, SetCookiesForUrl};
|
||||||
|
use net_traits::CookieSource::HTTP;
|
||||||
use net_traits::MessageData;
|
use net_traits::MessageData;
|
||||||
use net_traits::hosts::replace_hosts;
|
use net_traits::hosts::replace_hosts;
|
||||||
use net_traits::unwrap_websocket_protocol;
|
use net_traits::unwrap_websocket_protocol;
|
||||||
|
@ -485,6 +486,15 @@ impl Runnable for ConnectionEstablishedTask {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 5: Cookies.
|
// Step 5: Cookies.
|
||||||
|
if let Some(cookies) = self.headers.get_raw("set-cookie") {
|
||||||
|
for cookie in cookies.iter() {
|
||||||
|
if let Ok(cookie_value) = String::from_utf8(cookie.clone()) {
|
||||||
|
let _ = ws.global().r().resource_thread().send(SetCookiesForUrl(ws.url.clone(),
|
||||||
|
cookie_value,
|
||||||
|
HTTP));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Step 6.
|
// Step 6.
|
||||||
ws.upcast().fire_simple_event("open", global.r());
|
ws.upcast().fire_simple_event("open", global.r());
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[001.html]
|
|
||||||
type: testharness
|
|
||||||
[WebSockets: Cookie in request]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[002.html]
|
|
||||||
type: testharness
|
|
||||||
[WebSockets: Set-Cookie in response]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[003.html]
|
|
||||||
type: testharness
|
|
||||||
[WebSockets: sending HttpOnly cookies in ws request]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[005.html]
|
|
||||||
type: testharness
|
|
||||||
[WebSockets: setting HttpOnly cookies in ws response, checking ws request]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[007.html]
|
|
||||||
type: testharness
|
|
||||||
[WebSockets: when to process set-cookie fields in ws response]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue