-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Summer of Code 2014: Implement XMLHttpRequest
Josh Matthews edited this page Mar 7, 2014
·
7 revisions
Mentor: Josh Matthews (jdm in #servo on irc.mozilla.org, josh@joshmatthews.net)
Other knowledgeable people: Ms2ger, jgraham in #servo
This project will focus on synchronous and asynchronous GET and POST requests. There are multiple parts:
- create a Rust type that implements a very simplified version of the WebIDL interface supporting synchronous requests (the constructor,
open
,send
,status
,statusText
,responseText
) - implement a synchronous GET request using something like
load_whole_resource
inresource_task.rs
. Create tests that demonstrate that it works. - create a simple test harness that runs a Python HTTP server to allow for automated testing.
- implement asynchronous GET requests that integrate with the main event loop in
script_task.rs
(seeScriptMsg
) - make the Rust XMLHttpRequest type implement the XMLHttpRequestEventTarget interface, focusing on simple events such as
onerror
andonload
to start (see other EventTarget-derived examples such as Window and its associated load event). Dispatch these events based on events received in the ScriptTask event loop. - implement
readyState
and theonreadystatechange
event. - implement a basic
responseType
that supports fetching either JSON or plain text - implement other APIs such as
abort
(andonabort
),timeout
(andontimeout
),setRequestHeader
,getResponseHeader
, andgetAllResponseHeaders
- assuming that https://github.com/chris-morgan/rust-http/pull/23 is complete, implement a very basic
send
that supports sending a string as the request content
Throughout this process, find good representative samples of real web sites that use XHR and figure out what is required to make them work correctly. In addition, strive to write tests for each new feature added to the Servo XHR implementation.
Spec: http://xhr.spec.whatwg.org/
Reference: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
Gecko's implementation: nsXMLHttpRequest.cpp and nsXMLHttpRequest.h
- read DOM code (src/components/script/dom), and understand the relationship between WebIDL interfaces (src/components/script/dom/webidls) and their Rust implementations
- read code that dispatches DOM events (search for the "load" event in script_task.rs)
- understand how the ScriptTask event loop interacts with DOM code (see the timer API in window.rs, for example)
- read code that interacts with the networking stack (see the HTML parser in hubbub_html_parser.rs, for example)
- understand the rust-http API and how it relates to the needs of XMLHttpRequest
- gain experience using Rust by solving an easy DOM issue. Please leave a comment saying that you're working on it.