зеркало из https://github.com/mozilla/gecko-dev.git
servo: Begin supporting http:// urls
Source-Repo: https://github.com/servo/servo Source-Revision: 38c6e99e2082b7b25b468746e00b7d53ce300c77
This commit is contained in:
Родитель
a16038af5d
Коммит
10aae91785
|
@ -184,7 +184,6 @@ fn spawn_html_lexer_task(-url: url, resource_task: ResourceTask) -> port<Token>
|
|||
let html_chan = chan(html_port);
|
||||
|
||||
task::spawn(|| {
|
||||
assert url.path.ends_with(~".html");
|
||||
let input_port = port();
|
||||
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 {
|
||||
let loaders = ~[
|
||||
(~"file", file_loader::factory)
|
||||
(~"file", file_loader::factory),
|
||||
(~"http", http_loader::factory)
|
||||
];
|
||||
create_resource_task_with_loaders(loaders)
|
||||
}
|
||||
|
|
|
@ -114,6 +114,7 @@ mod engine;
|
|||
mod resource {
|
||||
mod resource_task;
|
||||
mod file_loader;
|
||||
mod http_loader;
|
||||
}
|
||||
|
||||
import servo_text = text;
|
||||
|
|
Загрузка…
Ссылка в новой задаче