1- mod grpc;
21mod hex_dump;
32mod hex_stream;
43mod msgpack;
54mod protobuf;
65
7- pub use grpc:: GRPC ;
86pub use hex_dump:: HexDump ;
97pub use hex_stream:: HexStream ;
108pub use msgpack:: MsgPack ;
119pub use protobuf:: Protobuf ;
10+ pub use protobuf:: GRPC ;
1211
1312use anyhow:: Result ;
1413use mitmproxy_highlight:: Language ;
14+ use std:: path:: Path ;
1515
1616pub trait Metadata {
1717 /// The HTTP `content-type` of this message.
1818 fn content_type ( & self ) -> Option < & str > ;
1919 /// Get an HTTP header value by name.
2020 /// `name` is case-insensitive.
2121 fn get_header ( & self , name : & str ) -> Option < String > ;
22+ /// Get the path from the flow's request.
23+ fn get_path ( & self ) -> Option < & str > {
24+ None
25+ }
26+ /// Check if this is an HTTP request.
27+ fn is_http_request ( & self ) -> bool {
28+ false
29+ }
30+ /// Get the protobuf definitions for this message.
31+ fn protobuf_definitions ( & self ) -> Option < & Path > {
32+ None
33+ }
2234}
2335
2436/// See https://docs.mitmproxy.org/dev/api/mitmproxy/contentviews.html
@@ -55,11 +67,15 @@ pub trait Reencode: Send + Sync {
5567// no cfg(test) gate because it's used in benchmarks as well
5668pub mod test {
5769 use crate :: Metadata ;
70+ use std:: path:: Path ;
5871
5972 #[ derive( Default ) ]
6073 pub struct TestMetadata {
6174 pub content_type : Option < String > ,
6275 pub headers : std:: collections:: HashMap < String , String > ,
76+ pub protobuf_definitions : Option < std:: path:: PathBuf > ,
77+ pub path : Option < String > ,
78+ pub is_http_request : bool ,
6379 }
6480
6581 impl TestMetadata {
@@ -72,6 +88,21 @@ pub mod test {
7288 self . headers . insert ( name. to_lowercase ( ) , value. to_string ( ) ) ;
7389 self
7490 }
91+
92+ pub fn with_path ( mut self , path : & str ) -> Self {
93+ self . path = Some ( path. to_string ( ) ) ;
94+ self
95+ }
96+
97+ pub fn with_protobuf_definitions < P : AsRef < Path > > ( mut self , definitions : P ) -> Self {
98+ self . protobuf_definitions = Some ( definitions. as_ref ( ) . to_path_buf ( ) ) ;
99+ self
100+ }
101+
102+ pub fn with_is_http_request ( mut self , is_http_request : bool ) -> Self {
103+ self . is_http_request = is_http_request;
104+ self
105+ }
75106 }
76107
77108 impl Metadata for TestMetadata {
@@ -80,7 +111,19 @@ pub mod test {
80111 }
81112
82113 fn get_header ( & self , name : & str ) -> Option < String > {
83- self . headers . get ( & name. to_lowercase ( ) ) . cloned ( )
114+ self . headers . get ( name) . cloned ( )
115+ }
116+
117+ fn get_path ( & self ) -> Option < & str > {
118+ self . path . as_deref ( )
119+ }
120+
121+ fn protobuf_definitions ( & self ) -> Option < & Path > {
122+ self . protobuf_definitions . as_deref ( )
123+ }
124+
125+ fn is_http_request ( & self ) -> bool {
126+ self . is_http_request
84127 }
85128 }
86129}
0 commit comments