mirror of
https://github.com/servo/servo.git
synced 2025-06-21 23:59:00 +01:00
Add rust-http to the build and begin using it to resolve http urls
This commit is contained in:
parent
6fe337e215
commit
232bdae8e6
5 changed files with 60 additions and 43 deletions
1
configure
vendored
1
configure
vendored
|
@ -480,6 +480,7 @@ CFG_SUBMODULES="\
|
||||||
support/css/rust-cssparser \
|
support/css/rust-cssparser \
|
||||||
support/geom/rust-geom \
|
support/geom/rust-geom \
|
||||||
support/harfbuzz/rust-harfbuzz \
|
support/harfbuzz/rust-harfbuzz \
|
||||||
|
support/http/rust-http \
|
||||||
support/hubbub/libhubbub \
|
support/hubbub/libhubbub \
|
||||||
support/hubbub/rust-hubbub \
|
support/hubbub/rust-hubbub \
|
||||||
support/layers/rust-layers \
|
support/layers/rust-layers \
|
||||||
|
|
|
@ -2,47 +2,63 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use resource_task::{Payload, Done, LoaderTask};
|
use resource_task::{ProgressMsg, Payload, Done, LoaderTask};
|
||||||
|
|
||||||
use std::comm::SharedChan;
|
use std::cell::Cell;
|
||||||
use std::task;
|
use std::vec;
|
||||||
use http_client::uv_http_request;
|
use extra::url::Url;
|
||||||
use http_client;
|
use http::client::RequestWriter;
|
||||||
|
use http::method::Get;
|
||||||
|
use http::headers::HeaderEnum;
|
||||||
|
use std::rt::io::Reader;
|
||||||
|
use std::rt::io::net::ip::SocketAddr;
|
||||||
|
|
||||||
pub fn factory() -> LoaderTask {
|
pub fn factory() -> LoaderTask {
|
||||||
let f: LoaderTask = |url, progress_chan| {
|
let f: LoaderTask = |url, progress_chan| {
|
||||||
assert!(url.scheme == ~"http");
|
let url = Cell::new(url);
|
||||||
|
let progress_chan = Cell::new(progress_chan);
|
||||||
let progress_chan = SharedChan::new(progress_chan);
|
spawn(|| load(url.take(), progress_chan.take()))
|
||||||
do task::spawn {
|
|
||||||
debug!("http_loader: requesting via http: %?", url.clone());
|
|
||||||
let mut request = uv_http_request(url.clone());
|
|
||||||
let errored = @mut false;
|
|
||||||
let url = url.clone();
|
|
||||||
{
|
|
||||||
let progress_chan = progress_chan.clone();
|
|
||||||
do request.begin |event| {
|
|
||||||
let url = url.clone();
|
|
||||||
match event {
|
|
||||||
http_client::Status(*) => { }
|
|
||||||
http_client::Payload(data) => {
|
|
||||||
debug!("http_loader: got data from %?", url);
|
|
||||||
let data = data.take();
|
|
||||||
progress_chan.send(Payload(data));
|
|
||||||
}
|
|
||||||
http_client::Error(*) => {
|
|
||||||
debug!("http_loader: error loading %?", url);
|
|
||||||
*errored = true;
|
|
||||||
progress_chan.send(Done(Err(())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !*errored {
|
|
||||||
progress_chan.send(Done(Ok(())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn load(url: Url, progress_chan: Chan<ProgressMsg>) {
|
||||||
|
assert!(url.scheme == ~"http");
|
||||||
|
|
||||||
|
info!("requesting %s", url.to_str());
|
||||||
|
|
||||||
|
let mut request = ~RequestWriter::new(Get, url.clone());
|
||||||
|
request.remote_addr = Some(url_to_socket_addr(&url));
|
||||||
|
let mut response = match request.read_response() {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(_) => {
|
||||||
|
progress_chan.send(Done(Err(())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loop {
|
||||||
|
for header in response.headers.iter() {
|
||||||
|
info!(" - %s: %s", header.header_name(), header.header_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut buf = vec::with_capacity(1024);
|
||||||
|
unsafe { vec::raw::set_len(&mut buf, 1024) };
|
||||||
|
match response.read(buf) {
|
||||||
|
Some(len) => {
|
||||||
|
unsafe { vec::raw::set_len(&mut buf, len) };
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
progress_chan.send(Done(Ok(())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
progress_chan.send(Payload(buf));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Quick hack to convert ip addresses to SocketAddr
|
||||||
|
fn url_to_socket_addr(url: &Url) -> SocketAddr {
|
||||||
|
let host_and_port = fmt!("%s:%s", url.host, url.port.clone().unwrap_or_default(~"80"));
|
||||||
|
FromStr::from_str(host_and_port).expect("couldn't parse host as IP address")
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#[crate_type = "lib"];
|
#[crate_type = "lib"];
|
||||||
|
|
||||||
extern mod geom;
|
extern mod geom;
|
||||||
//extern mod http_client;
|
extern mod http;
|
||||||
extern mod servo_util (name = "util");
|
extern mod servo_util (name = "util");
|
||||||
extern mod stb_image;
|
extern mod stb_image;
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
|
@ -25,7 +25,7 @@ pub mod image {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod file_loader;
|
pub mod file_loader;
|
||||||
//pub mod http_loader;
|
pub mod http_loader;
|
||||||
pub mod image_cache_task;
|
pub mod image_cache_task;
|
||||||
pub mod local_image_cache;
|
pub mod local_image_cache;
|
||||||
pub mod resource_task;
|
pub mod resource_task;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
//! A task that takes a URL and streams back the binary data.
|
//! A task that takes a URL and streams back the binary data.
|
||||||
|
|
||||||
use file_loader;
|
use file_loader;
|
||||||
//use http_loader;
|
use http_loader;
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::comm::{Chan, Port, SharedChan};
|
use std::comm::{Chan, Port, SharedChan};
|
||||||
|
@ -43,10 +43,10 @@ pub type LoaderTask = ~fn(url: Url, Chan<ProgressMsg>);
|
||||||
/// Create a ResourceTask with the default loaders
|
/// Create a ResourceTask with the default loaders
|
||||||
pub fn ResourceTask() -> ResourceTask {
|
pub fn ResourceTask() -> ResourceTask {
|
||||||
let file_loader_factory: LoaderTaskFactory = file_loader::factory;
|
let file_loader_factory: LoaderTaskFactory = file_loader::factory;
|
||||||
//let http_loader_factory: LoaderTaskFactory = http_loader::factory;
|
let http_loader_factory: LoaderTaskFactory = http_loader::factory;
|
||||||
let loaders = ~[
|
let loaders = ~[
|
||||||
(~"file", file_loader_factory),
|
(~"file", file_loader_factory),
|
||||||
//(~"http", http_loader_factory)
|
(~"http", http_loader_factory)
|
||||||
];
|
];
|
||||||
create_resource_task_with_loaders(loaders)
|
create_resource_task_with_loaders(loaders)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit c8c703e88be23ec34e62fbbb92bca1b3aac93ebe
|
Subproject commit b96039c69e77983f497d43306d3995e380ebec5b
|
Loading…
Add table
Add a link
Reference in a new issue