Auto merge of #6611 - jdm:websocketorigin, r=jdm

Add Origin header to WebSocket connections.

Closes #6532.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6611)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-07-13 23:39:16 -06:00
commit 0fb9f22ff7
9 changed files with 29 additions and 11 deletions

View file

@ -32,6 +32,7 @@ use websocket::client::receiver::Receiver;
use websocket::stream::WebSocketStream; use websocket::stream::WebSocketStream;
use websocket::client::request::Url; use websocket::client::request::Url;
use websocket::Client; use websocket::Client;
use websocket::header::Origin;
#[derive(JSTraceable, PartialEq, Copy, Clone)] #[derive(JSTraceable, PartialEq, Copy, Clone)]
enum WebSocketRequestState { enum WebSocketRequestState {
@ -139,7 +140,7 @@ impl WebSocket {
// TODO Client::connect does not conform to RFC 6455 // TODO Client::connect does not conform to RFC 6455
// see https://github.com/cyderize/rust-websocket/issues/38 // see https://github.com/cyderize/rust-websocket/issues/38
let request = match Client::connect(url) { let mut request = match Client::connect(url) {
Ok(request) => request, Ok(request) => request,
Err(_) => { Err(_) => {
let global_root = ws.r().global.root(); let global_root = ws.r().global.root();
@ -149,6 +150,7 @@ impl WebSocket {
return Ok(ws); return Ok(ws);
} }
}; };
request.headers.set(Origin(global.get_url().serialize()));
let response = request.send().unwrap(); let response = request.send().unwrap();
response.validate().unwrap(); response.validate().unwrap();

View file

@ -1,3 +1,6 @@
[010.html] [010.html]
type: testharness type: testharness
expected: CRASH expected: TIMEOUT
[WebSockets: protocol in response but no requested protocol]
expected: TIMEOUT

View file

@ -1,3 +1,6 @@
[011.html] [011.html]
type: testharness type: testharness
expected: CRASH expected: TIMEOUT
[WebSockets: protocol mismatch]
expected: TIMEOUT

View file

@ -1,3 +1,6 @@
[012.html] [012.html]
type: testharness type: testharness
expected: CRASH expected: TIMEOUT
[WebSockets: no protocol in response]
expected: TIMEOUT

View file

@ -1,3 +1,5 @@
[002.html] [002.html]
type: testharness type: testharness
expected: CRASH [WebSockets: Set-Cookie in response]
expected: FAIL

View file

@ -1,3 +0,0 @@
[004.html]
type: testharness
expected: CRASH

View file

@ -1,3 +1,6 @@
[005.html] [005.html]
type: testharness type: testharness
expected: CRASH expected: TIMEOUT
[WebSockets: setting HttpOnly cookies in ws response, checking ws request]
expected: TIMEOUT

View file

@ -1,3 +1,5 @@
[007.html] [007.html]
type: testharness type: testharness
expected: CRASH [WebSockets: when to process set-cookie fields in ws response]
expected: FAIL

View file

@ -1,3 +1,6 @@
[005.html] [005.html]
type: testharness type: testharness
expected: CRASH expected: TIMEOUT
[WebSockets: proper first line]
expected: TIMEOUT