mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
1. Add an Option<Pipeline_id> field to the LoadData struct, and a corresponding parameter to LoadData::new()
2. Change addEvent in the NetworkEventActor to add_request and add_response
This commit is contained in:
parent
6e91ebb1fe
commit
01eb31ae8a
18 changed files with 152 additions and 151 deletions
|
@ -3,28 +3,14 @@
|
|||
* 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.
|
||||
/// Handles interaction with the remote web console on network events (HTTP requests, responses) 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 devtools_traits::{DevtoolsControlMsg, NetworkEvent};
|
||||
|
||||
use collections::BTreeMap;
|
||||
use core::cell::RefCell;
|
||||
use std::fmt;
|
||||
use rustc_serialize::json::{self, Json, ToJson};
|
||||
use rustc_serialize::json;
|
||||
use std::net::TcpStream;
|
||||
use std::num::Float;
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::borrow::IntoCow;
|
||||
|
||||
use url::Url;
|
||||
use hyper::header::Headers;
|
||||
use hyper::http::RawStatus;
|
||||
|
@ -43,12 +29,10 @@ struct HttpResponse {
|
|||
body: Option<Vec<u8>>
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable)]
|
||||
struct GetRequestHeadersReply {
|
||||
from: String,
|
||||
headers: String,
|
||||
headerSize: u8,
|
||||
rawHeaders: String
|
||||
pub struct NetworkEventActor {
|
||||
pub name: String,
|
||||
request: HttpRequest,
|
||||
response: HttpResponse,
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable)]
|
||||
|
@ -57,25 +41,27 @@ pub struct EventActor {
|
|||
pub url: String,
|
||||
pub method: String,
|
||||
pub startedDateTime: String,
|
||||
pub isXHR: String,
|
||||
pub private: String
|
||||
pub isXHR: bool,
|
||||
pub private: bool
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable)]
|
||||
pub struct ResponseStartMsg {
|
||||
pub httpVersion: String,
|
||||
pub remoteAddress: String,
|
||||
pub remotePort: u8,
|
||||
pub remotePort: u32,
|
||||
pub status: String,
|
||||
pub statusText: String,
|
||||
pub headersSize: u8,
|
||||
pub headersSize: u32,
|
||||
pub discardResponseBody: bool,
|
||||
}
|
||||
|
||||
pub struct NetworkEventActor {
|
||||
pub name: String,
|
||||
request: HttpRequest,
|
||||
response: HttpResponse,
|
||||
#[derive(RustcEncodable)]
|
||||
struct GetRequestHeadersReply {
|
||||
from: String,
|
||||
headers: Vec<String>,
|
||||
headerSize: u8,
|
||||
rawHeaders: String
|
||||
}
|
||||
|
||||
impl Actor for NetworkEventActor {
|
||||
|
@ -86,47 +72,35 @@ impl Actor for NetworkEventActor {
|
|||
fn handle_message(&self,
|
||||
_registry: &ActorRegistry,
|
||||
msg_type: &str,
|
||||
msg: &json::Object,
|
||||
_msg: &json::Object,
|
||||
stream: &mut TcpStream) -> Result<bool, ()> {
|
||||
Ok(match msg_type {
|
||||
|
||||
"getRequestHeaders" => {
|
||||
println!("getRequestHeaders");
|
||||
// TODO: Pass the correct values for headers, headerSize, rawHeaders
|
||||
let msg = GetRequestHeadersReply {
|
||||
from: self.name(),
|
||||
headers: "headers".to_string(),
|
||||
headers: Vec::new(),
|
||||
headerSize: 10,
|
||||
rawHeaders: "Raw headers".to_string(),
|
||||
rawHeaders: "Raw headers".to_string(),
|
||||
};
|
||||
stream.write_json_packet(&msg);
|
||||
true
|
||||
}
|
||||
|
||||
"getRequestCookies" => {
|
||||
println!("getRequestCookies");
|
||||
true
|
||||
false
|
||||
}
|
||||
|
||||
"getRequestPostData" => {
|
||||
println!("getRequestPostData");
|
||||
true
|
||||
false
|
||||
}
|
||||
|
||||
"getResponseHeaders" => {
|
||||
println!("getResponseHeaders");
|
||||
true
|
||||
false
|
||||
}
|
||||
|
||||
"getResponseCookies" => {
|
||||
println!("getResponseCookies");
|
||||
true
|
||||
false
|
||||
}
|
||||
|
||||
"getResponseContent" => {
|
||||
println!("getResponseContent");
|
||||
true
|
||||
false
|
||||
}
|
||||
|
||||
_ => false
|
||||
})
|
||||
}
|
||||
|
@ -147,37 +121,37 @@ impl NetworkEventActor {
|
|||
status: None,
|
||||
body: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addEvent(&mut self, network_event: NetworkEvent) {
|
||||
match network_event {
|
||||
NetworkEvent::HttpRequest(url, method, headers, body) => {
|
||||
self.request.url = url.serialize();
|
||||
self.request.method = method.clone();
|
||||
self.request.headers = headers.clone();
|
||||
self.request.body = body;
|
||||
}
|
||||
NetworkEvent::HttpResponse(headers, status, body) => {
|
||||
self.response.headers = headers.clone();
|
||||
self.response.status = status.clone();
|
||||
self.response.body = body.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_request(&mut self, url: Url, method: Method, headers: Headers, body: Option<Vec<u8>>) {
|
||||
self.request.url = url.serialize();
|
||||
self.request.method = method.clone();
|
||||
self.request.headers = headers.clone();
|
||||
self.request.body = body;
|
||||
}
|
||||
|
||||
pub fn add_response(&mut self, headers: Option<Headers>, status: Option<RawStatus>, body: Option<Vec<u8>>) {
|
||||
self.response.headers = headers.clone();
|
||||
self.response.status = status.clone();
|
||||
self.response.body = body.clone();
|
||||
}
|
||||
|
||||
pub fn get_event_actor(&self) -> EventActor {
|
||||
// TODO: Send the correct values for startedDateTime, isXHR, private
|
||||
EventActor {
|
||||
actor: self.name(),
|
||||
url: self.request.url.clone(),
|
||||
method: format!("{}", self.request.method),
|
||||
startedDateTime: "2015-04-22T20:47:08.545Z".to_string(),
|
||||
isXHR: "false".to_string(),
|
||||
private: "false".to_string(),
|
||||
isXHR: false,
|
||||
private: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_response_start(&self) -> ResponseStartMsg {
|
||||
// TODO: Send the correct values for all these fields.
|
||||
// This is a fake message.
|
||||
ResponseStartMsg {
|
||||
httpVersion: "HTTP/1.1".to_string(),
|
||||
remoteAddress: "63.245.217.43".to_string(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue