servo: Begin supporting http:// urls

Source-Repo: https://github.com/servo/servo
Source-Revision: 38c6e99e2082b7b25b468746e00b7d53ce300c77
This commit is contained in:
Brian Anderson 2012-07-27 19:54:13 -07:00
Родитель a16038af5d
Коммит 10aae91785
4 изменённых файлов: 51 добавлений и 2 удалений

Просмотреть файл

@ -184,7 +184,6 @@ fn spawn_html_lexer_task(-url: url, resource_task: ResourceTask) -> port<Token>
let html_chan = chan(html_port); let html_chan = chan(html_port);
task::spawn(|| { task::spawn(|| {
assert url.path.ends_with(~".html");
let input_port = port(); let input_port = port();
resource_task.send(Load(url, input_port.chan())); resource_task.send(Load(url, input_port.chan()));

Просмотреть файл

@ -0,0 +1,48 @@
export factory;
import comm::{chan, methods};
import task::spawn;
import resource_task::{ProgressMsg, Payload, Done};
import std::net::url::url;
import http_client::{
uv_http_request,
Uri
};
import result::{ok, err};
fn factory(url: url, progress_chan: chan<ProgressMsg>) {
assert url.scheme == ~"http";
do spawn {
#debug("http_loader: requesting via http: %?", url);
let request = uv_http_request(url_to_http_client_uri(url));
let errored = @mut false;
do request.begin |event| {
alt event {
http_client::Status(*) { }
http_client::Payload(data) {
#debug("http_loader: got data from %?", url);
let mut crap = none;
*data <-> crap;
progress_chan.send(Payload(option::unwrap(crap)));
}
http_client::Error(*) {
#debug("http_loader: error loading %?", url);
*errored = true;
progress_chan.send(Done(err(())));
}
}
}
if !*errored {
progress_chan.send(Done(ok(())));
}
}
}
fn url_to_http_client_uri(url: url) -> Uri {
{
host: url.host,
path: url.path
}
}

Просмотреть файл

@ -30,7 +30,8 @@ type LoaderTaskFactory = fn~(url: url, chan<ProgressMsg>);
fn ResourceTask() -> ResourceTask { fn ResourceTask() -> ResourceTask {
let loaders = ~[ let loaders = ~[
(~"file", file_loader::factory) (~"file", file_loader::factory),
(~"http", http_loader::factory)
]; ];
create_resource_task_with_loaders(loaders) create_resource_task_with_loaders(loaders)
} }

Просмотреть файл

@ -114,6 +114,7 @@ mod engine;
mod resource { mod resource {
mod resource_task; mod resource_task;
mod file_loader; mod file_loader;
mod http_loader;
} }
import servo_text = text; import servo_text = text;