add download
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
*.har
|
||||||
# ---> Rust
|
# ---> Rust
|
||||||
# Generated by Cargo
|
# Generated by Cargo
|
||||||
# will have compiled files and executables
|
# will have compiled files and executables
|
||||||
|
|||||||
32
src/cmd_download.rs
Normal file
32
src/cmd_download.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use std::fs;
|
||||||
|
use clap::{ Arg, ArgMatches, SubCommand, App, };
|
||||||
|
use crate::cmd::{ Command, CommandError, };
|
||||||
|
use crate::har::*;
|
||||||
|
|
||||||
|
pub struct CommandDownload;
|
||||||
|
|
||||||
|
impl Command for CommandDownload {
|
||||||
|
|
||||||
|
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||||
|
SubCommand::with_name(self.name()).about("Download subcommand")
|
||||||
|
.arg(Arg::with_name("FILE_NAME").required(true).help("Har file name"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"download"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
||||||
|
let file_name = sub_arg_matches.value_of("FILE_NAME").unwrap();
|
||||||
|
let har_str = fs::read_to_string(file_name)?;
|
||||||
|
let har: Har = serde_json::from_str(&har_str)?;
|
||||||
|
|
||||||
|
// println!("{:?}", har);
|
||||||
|
|
||||||
|
har.log.entries.iter().for_each(|e| {
|
||||||
|
println!("{:<100} {}", e.request.url, e.server_ip_address);
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
use clap::{ ArgMatches, SubCommand, App, };
|
|
||||||
use crate::cmd::{ Command, CommandError, };
|
|
||||||
|
|
||||||
pub struct CommandSample;
|
|
||||||
|
|
||||||
impl Command for CommandSample {
|
|
||||||
|
|
||||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
|
||||||
SubCommand::with_name(self.name()).about("Sample subcommand")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"sample"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandError {
|
|
||||||
println!("This is test command!");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
87
src/har.rs
87
src/har.rs
@@ -2,48 +2,95 @@ use serde::{Serialize, Deserialize};
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct HarCreator {
|
pub struct HarCreator {
|
||||||
name: String,
|
pub name: String,
|
||||||
version: String,
|
pub version: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct HarPageTimings {
|
pub struct HarPageTimings {
|
||||||
#[serde(rename = "onContentLoad")]
|
#[serde(rename = "onContentLoad")]
|
||||||
on_content_load: f64,
|
pub on_content_load: f64,
|
||||||
#[serde(rename = "onLoad")]
|
#[serde(rename = "onLoad")]
|
||||||
on_load: f64,
|
pub on_load: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct HarPage {
|
pub struct HarPage {
|
||||||
#[serde(rename = "startedDateTime")]
|
#[serde(rename = "startedDateTime")]
|
||||||
started_date_time: String,
|
pub started_date_time: String,
|
||||||
id: String,
|
pub id: String,
|
||||||
title: String,
|
pub title: String,
|
||||||
#[serde(rename = "pageTimings")]
|
#[serde(rename = "pageTimings")]
|
||||||
page_timings: HarPageTimings,
|
pub page_timings: HarPageTimings,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct HarHeader {
|
||||||
|
pub name: String,
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct HarQueryParam {
|
||||||
|
pub name: String,
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct HarCookie {
|
||||||
|
pub name: String,
|
||||||
|
pub value: String,
|
||||||
|
pub expires: Option<String>,
|
||||||
|
#[serde(rename = "httpOnly")]
|
||||||
|
pub http_only: bool,
|
||||||
|
pub secure: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct HarRequest {
|
||||||
|
pub method: String,
|
||||||
|
pub url: String,
|
||||||
|
#[serde(rename = "httpVersion")]
|
||||||
|
pub http_version: String,
|
||||||
|
pub headers: Vec<HarHeader>,
|
||||||
|
#[serde(rename = "queryString")]
|
||||||
|
pub query_string: Vec<HarQueryParam>,
|
||||||
|
pub cookies: Vec<HarCookie>,
|
||||||
|
#[serde(rename = "headersSize")]
|
||||||
|
pub headers_size: i64,
|
||||||
|
#[serde(rename = "bodySize")]
|
||||||
|
pub body_size: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct HarEntry {
|
pub struct HarEntry {
|
||||||
// startedDateTime
|
#[serde(rename = "startedDateTime")]
|
||||||
time: f64,
|
pub started_date_time: String,
|
||||||
// request
|
pub time: f64,
|
||||||
|
pub request: HarRequest,
|
||||||
// response
|
// response
|
||||||
// cache
|
// cache
|
||||||
// timings
|
// timings
|
||||||
// serverIPAddress
|
#[serde(rename = "serverIPAddress")]
|
||||||
|
pub server_ip_address: String,
|
||||||
// _initiator
|
// _initiator
|
||||||
// _priority
|
#[serde(rename = "_priority")]
|
||||||
// _resourceType
|
pub priority: String,
|
||||||
// connection
|
#[serde(rename = "_resourceType")]
|
||||||
pageref: String, // @see Harpage::id
|
pub resource_ype: String,
|
||||||
|
pub connection: Option<String>,
|
||||||
|
pub pageref: Option<String>, // @see Harpage::id
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct HarLog {
|
pub struct HarLog {
|
||||||
version: String,
|
pub version: String,
|
||||||
creator: HarCreator,
|
pub creator: HarCreator,
|
||||||
pages: Vec<HarPage>,
|
pub pages: Vec<HarPage>,
|
||||||
entries: Vec<HarEntry>,
|
pub entries: Vec<HarEntry>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Har {
|
||||||
|
pub log: HarLog,
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
use clap::App;
|
use clap::App;
|
||||||
|
|
||||||
mod cmd;
|
mod cmd;
|
||||||
mod cmd_sample;
|
mod cmd_download;
|
||||||
mod cmd_default;
|
mod cmd_default;
|
||||||
mod har;
|
mod har;
|
||||||
|
|
||||||
use cmd::{ Command, CommandError, };
|
use cmd::{ Command, CommandError, };
|
||||||
use cmd_sample::CommandSample;
|
use cmd_download::CommandDownload;
|
||||||
use cmd_default::CommandDefault;
|
use cmd_default::CommandDefault;
|
||||||
|
|
||||||
fn main() -> CommandError {
|
fn main() -> CommandError {
|
||||||
let commands = vec![
|
let commands: Vec<Box<dyn Command>> = vec![
|
||||||
CommandSample{},
|
Box::new(CommandDownload{}),
|
||||||
];
|
];
|
||||||
let mut app = App::new(env!("CARGO_PKG_NAME"))
|
let mut app = App::new(env!("CARGO_PKG_NAME"))
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
|
|||||||
Reference in New Issue
Block a user