@@ -14,22 +14,31 @@ use anyhow::Result;
1414use mitmproxy_highlight:: Language ;
1515
1616pub trait Metadata {
17+ /// The HTTP `content-type` of this message.
1718 fn content_type ( & self ) -> Option < & str > ;
1819}
1920
21+ /// See https://docs.mitmproxy.org/dev/api/mitmproxy/contentviews.html
22+ /// for API details.
2023pub trait Prettify : Send + Sync {
24+ /// The name for this contentview, e.g. `gRPC` or `Protobuf`.
25+ /// Favor brevity.
2126 fn name ( & self ) -> & str ;
2227
2328 fn instance_name ( & self ) -> String {
2429 self . name ( ) . to_lowercase ( ) . replace ( " " , "_" )
2530 }
2631
32+ /// The syntax highlighting that should be applied to the prettified output.
33+ /// This is useful for contentviews that prettify to JSON or YAML.
2734 fn syntax_highlight ( & self ) -> Language {
2835 Language :: None
2936 }
3037
38+ /// Pretty-print `data`.
3139 fn prettify ( & self , data : & [ u8 ] , metadata : & dyn Metadata ) -> Result < String > ;
3240
41+ /// Render priority - typically a float between 0 and 1 for builtin views.
3342 #[ allow( unused_variables) ]
3443 fn render_priority ( & self , data : & [ u8 ] , metadata : & dyn Metadata ) -> f64 {
3544 0.0
@@ -40,13 +49,27 @@ pub trait Reencode: Send + Sync {
4049 fn reencode ( & self , data : & str , metadata : & dyn Metadata ) -> Result < Vec < u8 > > ;
4150}
4251
43- #[ derive( Default ) ]
44- pub struct TestMetadata {
45- pub content_type : Option < String > ,
46- }
52+ // no cfg(test) gate because it's used in benchmarks as well
53+ pub mod test {
54+ use crate :: Metadata ;
55+
56+ #[ derive( Default ) ]
57+ pub struct TestMetadata {
58+ pub content_type : Option < String > ,
59+ }
4760
48- impl Metadata for TestMetadata {
49- fn content_type ( & self ) -> Option < & str > {
50- self . content_type . as_deref ( )
61+ impl TestMetadata {
62+ pub fn with_content_type ( mut self , content_type : & str ) -> Self {
63+ self . content_type = Some ( content_type. to_string ( ) ) ;
64+ self
65+ }
5166 }
67+
68+ impl Metadata for TestMetadata {
69+ fn content_type ( & self ) -> Option < & str > {
70+ self . content_type . as_deref ( )
71+ }
72+ }
73+
74+
5275}
0 commit comments