Check in for task 1,4 and 5

Adding pipelineID to httpresponse message, clearner code for task1

Commit for Refactored task

Unit tests

Removing extra whitespaces.

Removing extra whitespaces.

Removing tabs whitespaces

Making Code tidier.

Style issues Fix

Test-tidy Fixes
This commit is contained in:
Abhishek Kumar 2015-10-21 18:28:14 -04:00
parent 0d15101323
commit b7de946205
13 changed files with 96 additions and 34 deletions

View file

@ -264,6 +264,7 @@ pub struct HttpRequest {
pub method: Method,
pub headers: Headers,
pub body: Option<Vec<u8>>,
pub pipeline_id: PipelineId,
}
#[derive(Debug, PartialEq)]
@ -271,6 +272,7 @@ pub struct HttpResponse {
pub headers: Option<Headers>,
pub status: Option<RawStatus>,
pub body: Option<Vec<u8>>,
pub pipeline_id: PipelineId,
}
pub enum NetworkEvent {

View file

@ -26,6 +26,9 @@ path = "../plugins"
version = "0.6"
features = [ "serde-serialization" ]
[dependencies.msg]
path = "../msg"
[dependencies.ipc-channel]
git = "https://github.com/pcwalton/ipc-channel"

View file

@ -23,6 +23,7 @@ use hyper::net::{Fresh, HttpsConnector, Openssl};
use hyper::status::{StatusClass, StatusCode};
use log;
use mime_classifier::MIMEClassifier;
use msg::constellation_msg::{PipelineId};
use net_traits::ProgressMsg::{Done, Payload};
use net_traits::hosts::replace_hosts;
use net_traits::{CookieSource, IncludeSubdomains, LoadConsumer, LoadData, Metadata};
@ -446,10 +447,12 @@ fn send_request_to_devtools(devtools_chan: Option<Sender<DevtoolsControlMsg>>,
url: Url,
method: Method,
headers: Headers,
body: Option<Vec<u8>>) {
body: Option<Vec<u8>>,
pipeline_id: PipelineId) {
if let Some(ref chan) = devtools_chan {
let request = DevtoolsHttpRequest { url: url, method: method, headers: headers, body: body };
let request = DevtoolsHttpRequest {
url: url, method: method, headers: headers, body: body, pipeline_id: pipeline_id };
let net_event = NetworkEvent::HttpRequest(request);
let msg = ChromeToDevtoolsControlMsg::NetworkEvent(request_id, net_event);
@ -460,9 +463,10 @@ fn send_request_to_devtools(devtools_chan: Option<Sender<DevtoolsControlMsg>>,
fn send_response_to_devtools(devtools_chan: Option<Sender<DevtoolsControlMsg>>,
request_id: String,
headers: Option<Headers>,
status: Option<RawStatus>) {
status: Option<RawStatus>,
pipeline_id: PipelineId) {
if let Some(ref chan) = devtools_chan {
let response = DevtoolsHttpResponse { headers: headers, status: status, body: None };
let response = DevtoolsHttpResponse { headers: headers, status: status, body: None, pipeline_id: pipeline_id };
let net_event_response = NetworkEvent::HttpResponse(response);
let msg = ChromeToDevtoolsControlMsg::NetworkEvent(request_id, net_event_response);
@ -600,35 +604,30 @@ pub fn load<A>(load_data: LoadData,
//
// https://tools.ietf.org/html/rfc7231#section-6.4
let is_redirected_request = iters != 1;
let cloned_data;
let maybe_response = match load_data.data {
Some(ref data) if !is_redirected_request => {
req.headers_mut().set(ContentLength(data.len() as u64));
// TODO: Do this only if load_data has some pipeline_id, and send the pipeline_id
// in the message
send_request_to_devtools(
devtools_chan.clone(), request_id.clone(), url.clone(),
method.clone(), load_data.headers.clone(),
load_data.data.clone()
);
cloned_data = load_data.data.clone();
req.send(&load_data.data)
}
_ => {
if load_data.method != Method::Get && load_data.method != Method::Head {
req.headers_mut().set(ContentLength(0))
}
send_request_to_devtools(
devtools_chan.clone(), request_id.clone(), url.clone(),
method.clone(), load_data.headers.clone(),
None
);
cloned_data = None;
req.send(&None)
}
};
if let Some(pipeline_id) = load_data.pipeline_id {
send_request_to_devtools(
devtools_chan.clone(), request_id.clone(), url.clone(),
method.clone(), request_headers.clone(),
cloned_data, pipeline_id
);
}
response = match maybe_response {
Ok(r) => r,
Err(LoadError::ConnectionAborted(reason)) => {
@ -704,13 +703,13 @@ pub fn load<A>(load_data: LoadData,
// --- Tell devtools that we got a response
// Send an HttpResponse message to devtools with the corresponding request_id
// TODO: Send this message only if load_data has a pipeline_id that is not None
// TODO: Send this message even when the load fails?
send_response_to_devtools(
devtools_chan, request_id,
metadata.headers.clone(), metadata.status.clone()
);
if let Some(pipeline_id) = load_data.pipeline_id {
send_response_to_devtools(
devtools_chan, request_id,
metadata.headers.clone(), metadata.status.clone(),
pipeline_id);
}
return StreamedResponse::from_http_response(response, metadata)
}
}

View file

@ -461,7 +461,7 @@ pub fn new_image_cache_task(resource_task: ResourceTask) -> ImageCacheTask {
placeholder_url.push("rippy.jpg");
let placeholder_image = match Url::from_file_path(&*placeholder_url) {
Ok(url) => {
match load_whole_resource(&resource_task, url) {
match load_whole_resource(&resource_task, url, None) {
Err(..) => {
debug!("image_cache_task: failed loading the placeholder.");
None

View file

@ -20,6 +20,7 @@ extern crate flate2;
extern crate brotli;
extern crate hyper;
extern crate ipc_channel;
extern crate msg;
extern crate net_traits;
extern crate openssl;
extern crate rustc_serialize;

View file

@ -383,10 +383,10 @@ pub enum ProgressMsg {
}
/// Convenience function for synchronously loading a whole resource.
pub fn load_whole_resource(resource_task: &ResourceTask, url: Url)
pub fn load_whole_resource(resource_task: &ResourceTask, url: Url, pipeline_id: Option<PipelineId>)
-> Result<(Metadata, Vec<u8>), String> {
let (start_chan, start_port) = ipc::channel().unwrap();
resource_task.send(ControlMsg::Load(LoadData::new(url, None),
resource_task.send(ControlMsg::Load(LoadData::new(url, pipeline_id),
LoadConsumer::Channel(start_chan))).unwrap();
let response = start_port.recv().unwrap();

View file

@ -78,6 +78,7 @@ impl DocumentLoader {
pending.load_async(listener)
}
/// Mark an in-progress network request complete.
pub fn finish_load(&mut self, load: LoadType) {
let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == load);

View file

@ -231,7 +231,7 @@ impl DedicatedWorkerGlobalScope {
let roots = RootCollection::new();
let _stack_roots_tls = StackRootTLS::new(&roots);
let (url, source) = match load_whole_resource(&init.resource_task, worker_url) {
let (url, source) = match load_whole_resource(&init.resource_task, worker_url, None) {
Err(_) => {
println!("error loading script {}", serialized_worker_url);
parent_sender.send(CommonScriptMsg::RunnableMsg(WorkerEvent,

View file

@ -193,7 +193,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
}
for url in urls {
let (url, source) = match load_whole_resource(&self.resource_task, url) {
let (url, source) = match load_whole_resource(&self.resource_task, url, None) {
Err(_) => return Err(Error::Network),
Ok((metadata, bytes)) => {
(metadata.final_url, String::from_utf8(bytes).unwrap())

View file

@ -1180,6 +1180,7 @@ dependencies = [
"hyper 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)",
"log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
"openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
@ -1201,6 +1202,7 @@ dependencies = [
"flate2 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)",
"msg 0.0.1",
"net 0.0.1",
"net_traits 0.0.1",
"time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",