use crate::vsl::record::{
VslIdent,
};
pub use crate::vsl::record::message::{
TimeStamp,
Duration,
ByteCount,
FetchMode,
Status,
Port,
FileDescriptor,
AclResult,
CompressionOperation,
CompressionDirection,
};
pub type Address = (String, Port);
#[derive(Debug, Clone, PartialEq)]
pub enum LogEntry {
Vcl(String),
VclError(String),
Debug(String),
Error(String),
FetchError(String),
Warning(String),
Acl(AclResult, String, Option<String>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Accounting {
pub recv_header: ByteCount,
pub recv_body: ByteCount,
pub recv_total: ByteCount,
pub sent_header: ByteCount,
pub sent_body: ByteCount,
pub sent_total: ByteCount,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PipeAccounting {
pub recv_total: ByteCount,
pub sent_total: ByteCount,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Handling {
Hit(VslIdent),
Miss,
Pass,
HitPass(VslIdent),
HitMiss(VslIdent, Duration),
Synth,
Pipe,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Compression {
pub operation: CompressionOperation,
pub bytes_in: ByteCount,
pub bytes_out: ByteCount,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Link<T> {
Unresolved(VslIdent, String),
Resolved(Box<T>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Proxy {
pub version: String,
pub client: Address,
pub server: Address,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SessionInfo {
pub ident: VslIdent,
pub open: TimeStamp,
pub local: Option<Address>,
pub remote: Address,
pub proxy: Option<Proxy>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ClientAccessRecord {
pub root: bool,
pub session: Option<SessionInfo>,
pub ident: VslIdent,
pub parent: VslIdent,
pub reason: String,
pub remote: Address,
pub transaction: ClientAccessTransaction,
pub start: TimeStamp,
pub end: Option<TimeStamp>,
pub handling: Handling,
pub compression: Option<Compression>,
pub log: Vec<LogEntry>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ClientAccessTransaction {
Full {
request: HttpRequest,
response: HttpResponse,
esi_records: Vec<Link<ClientAccessRecord>>,
backend_record: Option<Link<BackendAccessRecord>>,
process: Option<Duration>,
fetch: Option<Duration>,
ttfb: Duration,
serve: Duration,
accounting: Accounting,
},
RestartedEarly {
request: HttpRequest,
process: Option<Duration>,
restart_record: Link<ClientAccessRecord>,
},
RestartedLate {
request: HttpRequest,
response: HttpResponse,
backend_record: Option<Link<BackendAccessRecord>>,
process: Option<Duration>,
restart_record: Link<ClientAccessRecord>,
},
Bad {
request: Option<HttpRequest>,
response: HttpResponse,
ttfb: Duration,
serve: Duration,
accounting: Accounting,
},
Piped {
request: HttpRequest,
backend_record: Link<BackendAccessRecord>,
process: Option<Duration>,
ttfb: Option<Duration>,
accounting: PipeAccounting,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct CacheObject {
pub storage_type: String,
pub storage_name: String,
pub ttl: Option<Duration>,
pub grace: Option<Duration>,
pub keep: Option<Duration>,
pub since: TimeStamp,
pub origin: TimeStamp,
pub fetch_mode: Option<String>,
pub fetch_streamed: Option<bool>,
pub response: Option<HttpResponse>
}
#[derive(Debug, Clone, PartialEq)]
pub struct BackendConnection {
pub fd: FileDescriptor,
pub name: String,
pub remote: Option<Address>,
pub local: Address,
}
#[derive(Debug, Clone, PartialEq)]
pub struct BackendAccessRecord {
pub ident: VslIdent,
pub parent: VslIdent,
pub reason: String,
pub transaction: BackendAccessTransaction,
pub start: Option<TimeStamp>,
pub end: Option<TimeStamp>,
pub compression: Option<Compression>,
pub log: Vec<LogEntry>,
pub lru_nuked: u32,
}
#[derive(Debug, Clone, PartialEq)]
pub enum BackendAccessTransaction {
Full {
request: HttpRequest,
response: HttpResponse,
backend_connection: BackendConnection,
cache_object: CacheObject,
send: Duration,
wait: Duration,
ttfb: Duration,
fetch: Duration,
accounting: Accounting,
},
Failed {
request: HttpRequest,
synth_response: HttpResponse,
retry_record: Option<Link<BackendAccessRecord>>,
synth: Duration,
accounting: Accounting,
},
Aborted {
request: HttpRequest,
},
Abandoned {
request: HttpRequest,
response: HttpResponse,
backend_connection: BackendConnection,
retry_record: Option<Link<BackendAccessRecord>>,
send: Duration,
wait: Duration,
ttfb: Duration,
fetch: Option<Duration>,
},
Piped {
request: HttpRequest,
backend_connection: Option<BackendConnection>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct SessionRecord {
pub ident: VslIdent,
pub open: TimeStamp,
pub local: Option<Address>,
pub remote: Address,
pub proxy: Option<Proxy>,
pub client_records: Vec<Link<ClientAccessRecord>>,
pub duration: Duration,
pub close_reason: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HttpRequest {
pub protocol: String,
pub method: String,
pub url: String,
pub headers: Vec<(String, String)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HttpResponse {
pub status: Status,
pub reason: String,
pub protocol: String,
pub headers: Vec<(String, String)>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AccessRecord {
ClientAccess(ClientAccessRecord),
BackendAccess(BackendAccessRecord),
Session(SessionRecord),
}
impl<T> Link<T> {
pub fn is_unresolved(&self) -> bool {
match *self {
Link::Unresolved(..) => true,
_ => false
}
}
pub fn unwrap_unresolved(self) -> VslIdent {
match self {
Link::Unresolved(ident, _) => ident,
_ => panic!("unwrap_unresolved called on Link that was not Unresolved")
}
}
pub fn get_unresolved(&self) -> Option<VslIdent> {
match *self {
Link::Unresolved(ident, _) => Some(ident),
_ => None
}
}
pub fn is_resolved(&self) -> bool {
match *self {
Link::Resolved(_) => true,
_ => false
}
}
pub fn unwrap_resolved(self) -> Box<T> {
match self {
Link::Resolved(t) => t,
_ => panic!("unwrap_resolved called on Link that was not Resolved")
}
}
pub fn get_resolved(&self) -> Option<&T> {
match *self {
Link::Resolved(ref t) => Some(t.as_ref()),
_ => None
}
}
}
impl AccessRecord {
pub fn is_client_access(&self) -> bool {
match *self {
AccessRecord::ClientAccess(_) => true,
_ => false
}
}
pub fn unwrap_client_access(self) -> ClientAccessRecord {
match self {
AccessRecord::ClientAccess(access_record) => access_record,
_ => panic!("unwrap_client_access called on Record that was not ClientAccess")
}
}
pub fn is_backend_access(&self) -> bool {
match *self {
AccessRecord::BackendAccess(_) => true,
_ => false
}
}
pub fn unwrap_backend_access(self) -> BackendAccessRecord {
match self {
AccessRecord::BackendAccess(access_record) => access_record,
_ => panic!("unwrap_backend_access called on Record that was not BackendAccess")
}
}
pub fn is_session(&self) -> bool {
match *self {
AccessRecord::Session(_) => true,
_ => false,
}
}
pub fn unwrap_session(self) -> SessionRecord {
match self {
AccessRecord::Session(session_record) => session_record,
_ => panic!("unwrap_session called on AccessRecord that was not Session")
}
}
}