mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Return the parsed URL from WebSocket#url.
This commit is contained in:
parent
c3fc943c66
commit
4c0c60a4d6
3 changed files with 32 additions and 11 deletions
|
@ -47,7 +47,7 @@ no_jsmanaged_fields!(Receiver<WebSocketStream>);
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct WebSocket {
|
pub struct WebSocket {
|
||||||
eventtarget: EventTarget,
|
eventtarget: EventTarget,
|
||||||
url: DOMString,
|
url: Url,
|
||||||
global: GlobalField,
|
global: GlobalField,
|
||||||
ready_state: Cell<WebSocketRequestState>,
|
ready_state: Cell<WebSocketRequestState>,
|
||||||
sender: RefCell<Option<Sender<WebSocketStream>>>,
|
sender: RefCell<Option<Sender<WebSocketStream>>>,
|
||||||
|
@ -101,7 +101,7 @@ fn parse_web_socket_url(url_str: &str) -> Fallible<(Url, String, u16, String, bo
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebSocket {
|
impl WebSocket {
|
||||||
pub fn new_inherited(global: GlobalRef, url: DOMString) -> WebSocket {
|
pub fn new_inherited(global: GlobalRef, url: Url) -> WebSocket {
|
||||||
WebSocket {
|
WebSocket {
|
||||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::WebSocket),
|
eventtarget: EventTarget::new_inherited(EventTargetTypeId::WebSocket),
|
||||||
url: url,
|
url: url,
|
||||||
|
@ -121,25 +121,25 @@ impl WebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(global: GlobalRef, url: DOMString) -> Fallible<Root<WebSocket>> {
|
pub fn new(global: GlobalRef, url: DOMString) -> Fallible<Root<WebSocket>> {
|
||||||
|
// Step 1.
|
||||||
|
// FIXME extract the right variables once Client::connect
|
||||||
|
// implementation is fixed to follow the RFC 6455 properly.
|
||||||
|
let (url, _, _, _, _) = try!(parse_web_socket_url(&url));
|
||||||
|
|
||||||
/*TODO: This constructor is only a prototype, it does not accomplish the specs
|
/*TODO: This constructor is only a prototype, it does not accomplish the specs
|
||||||
defined here:
|
defined here:
|
||||||
http://html.spec.whatwg.org
|
http://html.spec.whatwg.org
|
||||||
Item 1 is already satisfied.
|
|
||||||
The remaining 8 items must be satisfied.
|
The remaining 8 items must be satisfied.
|
||||||
TODO: This constructor should be responsible for spawning a thread for the
|
TODO: This constructor should be responsible for spawning a thread for the
|
||||||
receive loop after ws.r().Open() - See comment
|
receive loop after ws.r().Open() - See comment
|
||||||
*/
|
*/
|
||||||
let ws = reflect_dom_object(box WebSocket::new_inherited(global, url),
|
let ws = reflect_dom_object(box WebSocket::new_inherited(global, url.clone()),
|
||||||
global,
|
global,
|
||||||
WebSocketBinding::Wrap);
|
WebSocketBinding::Wrap);
|
||||||
|
|
||||||
// FIXME extract the right variables once Client::connect implementation is
|
|
||||||
// fixed to follow the RFC 6455 properly
|
|
||||||
let (parsed_url, _, _, _, _) = try!(parse_web_socket_url(&ws.r().url));
|
|
||||||
|
|
||||||
// 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(parsed_url) {
|
let 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();
|
||||||
|
@ -198,7 +198,7 @@ impl<'a> WebSocketMethods for &'a WebSocket {
|
||||||
event_handler!(error, GetOnerror, SetOnerror);
|
event_handler!(error, GetOnerror, SetOnerror);
|
||||||
|
|
||||||
fn Url(self) -> DOMString {
|
fn Url(self) -> DOMString {
|
||||||
self.url.clone()
|
self.url.serialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ReadyState(self) -> u16 {
|
fn ReadyState(self) -> u16 {
|
||||||
|
|
|
@ -26471,7 +26471,16 @@
|
||||||
},
|
},
|
||||||
"local_changes": {
|
"local_changes": {
|
||||||
"deleted": [],
|
"deleted": [],
|
||||||
"items": {},
|
"items": {
|
||||||
|
"testharness": {
|
||||||
|
"websockets/interfaces/WebSocket/url/resolve.html": [
|
||||||
|
{
|
||||||
|
"path": "websockets/interfaces/WebSocket/url/resolve.html",
|
||||||
|
"url": "/websockets/interfaces/WebSocket/url/resolve.html"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"reftest_nodes": {}
|
"reftest_nodes": {}
|
||||||
},
|
},
|
||||||
"reftest_nodes": {
|
"reftest_nodes": {
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<!doctype html>
|
||||||
|
<title>WebSocket#url: resolving</title>
|
||||||
|
<script src=/resources/testharness.js></script>
|
||||||
|
<script src=/resources/testharnessreport.js></script>
|
||||||
|
<script src=../../../constants.js?pipe=sub></script>
|
||||||
|
<div id=log></div>
|
||||||
|
<script>
|
||||||
|
test(function() {
|
||||||
|
var ws = new WebSocket(SCHEME_DOMAIN_PORT + '/echo?foo%20bar baz');
|
||||||
|
assert_equals(ws.url, SCHEME_DOMAIN_PORT + '/echo?foo%20bar%20baz');
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue