Skip to content

Commit 5b39133

Browse files
committed
gRPC: incorporate existing protobuf definitions
1 parent 6aa4497 commit 5b39133

21 files changed

Lines changed: 1235 additions & 680 deletions

Cargo.lock

Lines changed: 39 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mitmproxy-contentviews/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ serde_yaml = "0.9"
2222
rmp-serde = "1.1"
2323
protobuf = "3.7.2"
2424
regex = "1.10.3"
25-
flate2 = "1.0.28"
25+
flate2 = "1.0"
26+
protobuf-parse = "3.7"
2627

2728
[dev-dependencies]
2829
criterion = "0.5.1"
2930

3031
[[bench]]
3132
name = "contentviews"
32-
harness = false
33+
harness = false

mitmproxy-contentviews/src/lib.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
1-
mod grpc;
21
mod hex_dump;
32
mod hex_stream;
43
mod msgpack;
54
mod protobuf;
65

7-
pub use grpc::GRPC;
86
pub use hex_dump::HexDump;
97
pub use hex_stream::HexStream;
108
pub use msgpack::MsgPack;
119
pub use protobuf::Protobuf;
10+
pub use protobuf::GRPC;
1211

1312
use anyhow::Result;
1413
use mitmproxy_highlight::Language;
14+
use std::path::Path;
1515

1616
pub 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
5668
pub 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

Comments
 (0)