Return the parsed URL from WebSocket#url.

This commit is contained in:
Ms2ger 2015-07-13 14:21:18 +02:00
parent c3fc943c66
commit 4c0c60a4d6
3 changed files with 32 additions and 11 deletions

View file

@ -47,7 +47,7 @@ no_jsmanaged_fields!(Receiver<WebSocketStream>);
#[dom_struct]
pub struct WebSocket {
eventtarget: EventTarget,
url: DOMString,
url: Url,
global: GlobalField,
ready_state: Cell<WebSocketRequestState>,
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 {
pub fn new_inherited(global: GlobalRef, url: DOMString) -> WebSocket {
pub fn new_inherited(global: GlobalRef, url: Url) -> WebSocket {
WebSocket {
eventtarget: EventTarget::new_inherited(EventTargetTypeId::WebSocket),
url: url,
@ -121,25 +121,25 @@ impl 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
defined here:
http://html.spec.whatwg.org
Item 1 is already satisfied.
The remaining 8 items must be satisfied.
TODO: This constructor should be responsible for spawning a thread for the
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,
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
// 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,
Err(_) => {
let global_root = ws.r().global.root();
@ -198,7 +198,7 @@ impl<'a> WebSocketMethods for &'a WebSocket {
event_handler!(error, GetOnerror, SetOnerror);
fn Url(self) -> DOMString {
self.url.clone()
self.url.serialize()
}
fn ReadyState(self) -> u16 {

View file

@ -26471,7 +26471,16 @@
},
"local_changes": {
"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": {

View file

@ -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>