mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Initial changes for devtools support for logging HTTP requests.
Add a NetworkEventActor to devtools/actors/ Authors: Ashritha Mohan Ram <amohanr@ncsu.edu> Himaja Valavala <hsvalava@ncsu.edu> Anand Chandrasekar <achandr9@ncsu.edu> Yiyang Wang <ywang95@ncsu.edu>
This commit is contained in:
parent
49aed6555d
commit
9f4a88bc48
10 changed files with 189 additions and 9 deletions
|
@ -16,6 +16,10 @@ path = "../msg"
|
|||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
||||
[dependencies]
|
||||
url = "0.2.16"
|
||||
hyper = "0.3"
|
||||
|
||||
[dependencies]
|
||||
time = "*"
|
||||
rustc-serialize = "0.3"
|
||||
|
|
68
components/devtools/actors/network_event.rs
Normal file
68
components/devtools/actors/network_event.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
/// Liberally derived from the [Firefox JS implementation](http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/webconsole.js).
|
||||
/// Mediates interaction between the remote web console and equivalent functionality (object
|
||||
/// inspection, JS evaluation, autocompletion) in Servo.
|
||||
|
||||
extern crate hyper;
|
||||
extern crate url;
|
||||
|
||||
use actor::{Actor, ActorRegistry};
|
||||
use protocol::JsonPacketStream;
|
||||
|
||||
use devtools_traits::DevtoolScriptControlMsg;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
|
||||
use collections::BTreeMap;
|
||||
use core::cell::RefCell;
|
||||
use rustc_serialize::json::{self, Json, ToJson};
|
||||
use std::net::TcpStream;
|
||||
use std::num::Float;
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
use url::Url;
|
||||
use hyper::header::Headers;
|
||||
use hyper::http::RawStatus;
|
||||
use hyper::method::Method;
|
||||
|
||||
#[derive(RustcEncodable)]
|
||||
pub struct HttpRequest {
|
||||
pub url: Url,
|
||||
//method: Method,
|
||||
//headers: Headers,
|
||||
pub body: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable)]
|
||||
pub struct NetworkEventActor {
|
||||
pub name: String,
|
||||
pub request: HttpRequest,
|
||||
}
|
||||
|
||||
impl Actor for NetworkEventActor {
|
||||
fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn handle_message(&self,
|
||||
_registry: &ActorRegistry,
|
||||
msg_type: &str,
|
||||
msg: &json::Object,
|
||||
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||
Ok(match msg_type {
|
||||
|
||||
"getRequestHeaders" => {
|
||||
//stream.write_json_packet(&msg);
|
||||
true
|
||||
}
|
||||
|
||||
"getRequestCookies" => {
|
||||
true
|
||||
}
|
||||
|
||||
_ => false
|
||||
})
|
||||
}
|
||||
}
|
|
@ -25,9 +25,13 @@ extern crate rustc_serialize;
|
|||
extern crate msg;
|
||||
extern crate time;
|
||||
extern crate util;
|
||||
extern crate url;
|
||||
extern crate hyper;
|
||||
|
||||
use actor::{Actor, ActorRegistry};
|
||||
use actors::console::ConsoleActor;
|
||||
use actors::network_event::NetworkEventActor;
|
||||
use actors::network_event::{HttpRequest};
|
||||
use actors::worker::WorkerActor;
|
||||
use actors::inspector::InspectorActor;
|
||||
use actors::root::RootActor;
|
||||
|
@ -49,6 +53,12 @@ use std::net::{TcpListener, TcpStream, Shutdown};
|
|||
use std::sync::{Arc, Mutex};
|
||||
use time::precise_time_ns;
|
||||
|
||||
use url::Url;
|
||||
|
||||
use hyper::header::Headers;
|
||||
use hyper::http::RawStatus;
|
||||
use hyper::method::Method;
|
||||
|
||||
mod actor;
|
||||
/// Corresponds to http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/
|
||||
mod actors {
|
||||
|
@ -60,6 +70,7 @@ mod actors {
|
|||
pub mod tab;
|
||||
pub mod timeline;
|
||||
pub mod worker;
|
||||
pub mod network_event;
|
||||
}
|
||||
mod protocol;
|
||||
|
||||
|
@ -80,6 +91,22 @@ struct ConsoleMsg {
|
|||
columnNumber: u32,
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable)]
|
||||
struct NetworkEventMsg {
|
||||
from: String,
|
||||
__type__: String,
|
||||
eventActor: EventActor,
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable)]
|
||||
struct EventActor {
|
||||
actor: NetworkEventActor,
|
||||
url: String,
|
||||
method: String,
|
||||
startedDateTime: String,
|
||||
isXHR: String,
|
||||
}
|
||||
|
||||
/// Spin up a devtools server that listens for connections on the specified port.
|
||||
pub fn start_server(port: u16) -> Sender<DevtoolsControlMsg> {
|
||||
let (sender, receiver) = channel();
|
||||
|
@ -252,6 +279,49 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
|||
return console_actor_name;
|
||||
}
|
||||
|
||||
fn handle_network_event(actors: Arc<Mutex<ActorRegistry>>,
|
||||
connections: RefCell<Vec<TcpStream>>,
|
||||
url: Url,
|
||||
method: Method,
|
||||
headers: Headers,
|
||||
body: Option<Vec<u8>>) {
|
||||
|
||||
//println!("handle_network_event");
|
||||
let mut actors = actors.lock().unwrap();
|
||||
|
||||
/* TODO: Maintain a HashMap that maps request/response ID to actor name.
|
||||
* Check if the map contains the ID of the request/response message.
|
||||
* If no actor exists, create a new one.
|
||||
* Store to stream(s) to the actor and retrieve them.
|
||||
*/
|
||||
|
||||
let actor = NetworkEventActor {
|
||||
name: actors.new_name("network_event"),
|
||||
request: HttpRequest {
|
||||
url: url.clone(),
|
||||
//method: method.clone(),
|
||||
//headers: headers.clone(),
|
||||
body: body.clone()
|
||||
},
|
||||
};
|
||||
|
||||
let msg = NetworkEventMsg {
|
||||
from: actor.name.clone(),
|
||||
__type__: "networkEvent".to_string(),
|
||||
eventActor: EventActor {
|
||||
actor: actor,
|
||||
url: url.serialize(),
|
||||
method: "".to_string(),
|
||||
startedDateTime: "".to_string(),
|
||||
isXHR: "false".to_string(),
|
||||
},
|
||||
};
|
||||
|
||||
for stream in connections.borrow_mut().iter_mut() {
|
||||
stream.write_json_packet(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
spawn_named("DevtoolsClientAcceptor".to_owned(), move || {
|
||||
// accept connections and process them, spawning a new task for each one
|
||||
for stream in listener.incoming() {
|
||||
|
@ -276,6 +346,15 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
|||
Ok(DevtoolsControlMsg::SendConsoleMessage(id, console_message)) =>
|
||||
handle_console_message(actors.clone(), id, console_message,
|
||||
&actor_pipelines),
|
||||
|
||||
Ok(DevtoolsControlMsg::HttpRequest(url, method, headers, body)) => {
|
||||
//println!("run_server: HttpRequest");
|
||||
let connections = RefCell::new(Vec::<TcpStream>::new());
|
||||
let mut stream = accepted_connections.get_mut(0).unwrap();
|
||||
connections.borrow_mut().push(stream.try_clone().unwrap());
|
||||
handle_network_event(actors.clone(), connections, url, method, headers, body);
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue