From 9322954f152fdec98c6419255afb207d4730ae4d Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Sun, 16 Aug 2015 17:50:37 +1000 Subject: [PATCH] Moves devtools messaging to functions --- components/net/http_loader.rs | 67 +++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 3abe0d89aec..6d83d34eaa8 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -331,6 +331,7 @@ fn set_cookies_from_response(url: Url, response: &HttpResponse, resource_mgr_cha } } +#[inline(always)] fn request_must_be_secured(url: &Url, resource_mgr_chan: &IpcSender) -> bool { let (tx, rx) = ipc::channel().unwrap(); resource_mgr_chan.send( @@ -417,6 +418,37 @@ enum Decoders { Plain(R) } +#[inline(always)] +fn send_request_to_devtools( + devtools_chan: Option>, request_id: String, + url: Url, method: Method, headers: Headers, body: Option>) { + + if let Some(ref chan) = devtools_chan { + let net_event = NetworkEvent::HttpRequest(url, method, headers, body); + chan.send(DevtoolsControlMsg::FromChrome( + ChromeToDevtoolsControlMsg::NetworkEvent( + request_id.clone(), + net_event + ) + ) + ).unwrap(); + } +} + +#[inline(always)] +fn send_response_to_devtools( + devtools_chan: Option>, request_id: String, + headers: Option, status: Option) { + if let Some(ref chan) = devtools_chan { + let net_event_response = + NetworkEvent::HttpResponse(headers.clone(), + status.clone(), + None); + chan.send(DevtoolsControlMsg::FromChrome( + ChromeToDevtoolsControlMsg::NetworkEvent(request_id, + net_event_response))).unwrap(); + } +} pub fn load(load_data: LoadData, resource_mgr_chan: IpcSender, devtools_chan: Option>, @@ -488,7 +520,6 @@ pub fn load(load_data: LoadData, set_default_accept_encoding(&mut request_headers); set_request_cookies(doc_url.clone(), &mut request_headers, &resource_mgr_chan); - // --- Send the request let mut req = try!(request_factory.create(url.clone(), method.clone())); *req.headers_mut() = request_headers; @@ -517,19 +548,15 @@ pub fn load(load_data: LoadData, } }; - // --- Tell devtools we've made a request - // Send an HttpRequest message to devtools with a unique request_id - // TODO: Do this only if load_data has some pipeline_id, and send the pipeline_id in the message let request_id = uuid::Uuid::new_v4().to_simple_string(); - if let Some(ref chan) = devtools_chan { - let net_event = NetworkEvent::HttpRequest(load_data.url.clone(), - method.clone(), - load_data.headers.clone(), - load_data.data.clone()); - chan.send(DevtoolsControlMsg::FromChrome( - ChromeToDevtoolsControlMsg::NetworkEvent(request_id.clone(), - net_event))).unwrap(); - } + + // 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(), + if is_redirected_request { None } else { load_data.data.clone() } + ); info!("got HTTP response {}, headers:", response.status()); if log_enabled!(log::LogLevel::Info) { @@ -608,15 +635,11 @@ pub fn load(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 - if let Some(ref chan) = devtools_chan { - let net_event_response = - NetworkEvent::HttpResponse(metadata.headers.clone(), - metadata.status.clone(), - None); - chan.send(DevtoolsControlMsg::FromChrome( - ChromeToDevtoolsControlMsg::NetworkEvent(request_id, - net_event_response))).unwrap(); - } + // TODO: Send this message even when the load fails? + send_response_to_devtools( + devtools_chan.clone(), request_id.clone(), + metadata.headers.clone(), metadata.status.clone() + ); return LoadResponse::from_http_response(response, metadata) }