Skip to content

Commit 14696de

Browse files
committed
move contentviews and syntax highlighter into separate crates
1 parent e67f83b commit 14696de

22 files changed

Lines changed: 137 additions & 71 deletions

File tree

Cargo.lock

Lines changed: 28 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[workspace]
22
members = [
33
".",
4+
"mitmproxy-contentviews",
5+
"mitmproxy-highlight",
46
"mitmproxy-rs",
57
"mitmproxy-linux",
68
"mitmproxy-linux-ebpf",
@@ -11,6 +13,8 @@ members = [
1113
]
1214
default-members = [
1315
".",
16+
"mitmproxy-contentviews",
17+
"mitmproxy-highlight",
1418
"mitmproxy-rs",
1519
"mitmproxy-linux",
1620
"mitmproxy-linux-ebpf-common",
@@ -68,15 +72,6 @@ internet-packet = { version = "0.2.3", features = ["smoltcp"] }
6872
data-encoding = "2.8.0"
6973
hickory-resolver = "0.25.1"
7074
socket2 = "0.5.9"
71-
serde = { version = "1.0", features = ["derive"] }
72-
serde_yaml = "0.9"
73-
rmp-serde = "1.1"
74-
protobuf = "3.7.2"
75-
regex = "1.10.3"
76-
tree-sitter-highlight = "0.25.3"
77-
tree-sitter-yaml = "0.7.0"
78-
tree-sitter-xml = "0.7.0"
79-
tree-sitter = "0.25.3"
8075

8176
[patch.crates-io]
8277
# tokio = { path = "../tokio/tokio" }
@@ -118,19 +113,10 @@ rand = "0.9"
118113
criterion = "0.5.1"
119114
hickory-server = "0.25.1"
120115

121-
122116
[[bench]]
123117
name = "process"
124118
harness = false
125119

126-
[[bench]]
127-
name = "contentviews"
128-
harness = false
129-
130-
[[bench]]
131-
name = "syntax_highlight"
132-
harness = false
133-
134120
[profile.release]
135121
codegen-units = 1
136122
lto = true

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ This repository contains mitmproxy's Rust bits, most notably:
2121
### Structure
2222

2323
- [`src/`](./src): The `mitmproxy` crate containing most of the "meat".
24+
- [`mitmproxy-contentviews/`](./mitmproxy-contentviews):
25+
Pretty-printers for (HTTP) message bodies.
26+
- [`mitmproxy-highlight/`](./mitmproxy-highlight):
27+
Syntax highlighting backend for mitmproxy and mitmdump.
2428
- [`mitmproxy-rs/`](./mitmproxy-rs): The `mitmproxy-rs` Python package,
2529
which provides Python bindings for the Rust crate using [PyO3](https://pyo3.rs/).
2630
Source and binary distributions are available [on PyPI](https://pypi.org/project/mitmproxy-rs/).

mitmproxy-contentviews/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "mitmproxy-contentviews"
3+
license = "MIT"
4+
authors.workspace = true
5+
version.workspace = true
6+
repository.workspace = true
7+
edition.workspace = true
8+
rust-version.workspace = true
9+
publish.workspace = true
10+
11+
[lints]
12+
workspace = true
13+
14+
[dependencies]
15+
anyhow = { version = "1.0.97", features = ["backtrace"] }
16+
log = "0.4.27"
17+
pretty-hex = "0.4.1"
18+
mitmproxy-highlight = { path = "../mitmproxy-highlight" }
19+
serde = { version = "1.0", features = ["derive"] }
20+
serde_yaml = "0.9"
21+
rmp-serde = "1.1"
22+
protobuf = "3.7.2"
23+
regex = "1.10.3"
24+
25+
[dev-dependencies]
26+
criterion = "0.5.1"
27+
28+
[[bench]]
29+
name = "contentviews"
30+
harness = false

benches/contentviews.rs renamed to mitmproxy-contentviews/benches/contentviews.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2-
use mitmproxy::contentviews;
3-
use mitmproxy::contentviews::{Prettify, Reencode, TestMetadata};
2+
use mitmproxy_contentviews::{MsgPack, Prettify, Protobuf, Reencode, TestMetadata};
43

54
fn criterion_benchmark(c: &mut Criterion) {
65
c.bench_function("protobuf-prettify", |b| {
76
b.iter(|| {
8-
contentviews::Protobuf.prettify(black_box(b"\n\x13gRPC testing server\x12\x07\n\x05Index\x12\x07\n\x05Empty\x12\x0c\n\nDummyUnary\x12\x0f\n\rSpecificError\x12\r\n\x0bRandomError\x12\x0e\n\x0cHeadersUnary\x12\x11\n\x0fNoResponseUnary"), &TestMetadata::default()).unwrap()
7+
Protobuf.prettify(black_box(b"\n\x13gRPC testing server\x12\x07\n\x05Index\x12\x07\n\x05Empty\x12\x0c\n\nDummyUnary\x12\x0f\n\rSpecificError\x12\r\n\x0bRandomError\x12\x0e\n\x0cHeadersUnary\x12\x11\n\x0fNoResponseUnary"), &TestMetadata::default()).unwrap()
98
})
109
});
1110

1211
c.bench_function("protobuf-reencode", |b| {
1312
b.iter(|| {
14-
contentviews::Protobuf.reencode(
13+
Protobuf.reencode(
1514
black_box("1: gRPC testing server\n2:\n- 1: Index\n- 1: Empty\n- 1: DummyUnary\n- 1: SpecificError\n- 1: RandomError\n- 1: HeadersUnary\n- 1: NoResponseUnary\n"),
1615
&TestMetadata::default()
1716
).unwrap()
@@ -31,15 +30,15 @@ fn criterion_benchmark(c: &mut Criterion) {
3130
];
3231
c.bench_function("msgpack-prettify", |b| {
3332
b.iter(|| {
34-
contentviews::MsgPack
33+
MsgPack
3534
.prettify(black_box(TEST_MSGPACK), &TestMetadata::default())
3635
.unwrap()
3736
})
3837
});
3938

4039
c.bench_function("msgpack-reencode", |b| {
4140
b.iter(|| {
42-
contentviews::MsgPack
41+
MsgPack
4342
.reencode(
4443
black_box(
4544
"\
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::contentviews::{Metadata, Prettify, Protobuf, Reencode};
2-
use crate::syntax_highlight::Language;
1+
use crate::{Metadata, Prettify, Protobuf, Reencode};
2+
use mitmproxy_highlight::Language;
33
use anyhow::{bail, Context, Result};
44
use serde::Deserialize;
55
use serde_yaml::Value;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::contentviews::hex_stream::is_binary;
2-
use crate::contentviews::{Metadata, Prettify};
1+
use crate::hex_stream::is_binary;
2+
use crate::{Metadata, Prettify};
33
use pretty_hex::{HexConfig, PrettyHex};
44

55
pub struct HexDump;
@@ -36,7 +36,7 @@ impl Prettify for HexDump {
3636
#[cfg(test)]
3737
mod tests {
3838
use super::*;
39-
use crate::contentviews::TestMetadata;
39+
use crate::TestMetadata;
4040

4141
#[test]
4242
fn prettify_simple() {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::contentviews::{Metadata, Prettify, Reencode};
1+
use crate::{Metadata, Prettify, Reencode};
22
use anyhow::{Context, Result};
33
use pretty_hex::{HexConfig, PrettyHex};
44
use std::num::ParseIntError;
@@ -64,7 +64,7 @@ impl Reencode for HexStream {
6464
#[cfg(test)]
6565
mod tests {
6666
use super::*;
67-
use crate::contentviews::TestMetadata;
67+
use crate::TestMetadata;
6868

6969
#[test]
7070
fn test_hex_stream() {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod protobuf;
66

77
use anyhow::Result;
88

9-
use crate::syntax_highlight;
9+
use mitmproxy_highlight::Language;
1010
pub use grpc::GRPC;
1111
pub use hex_dump::HexDump;
1212
pub use hex_stream::HexStream;
@@ -24,8 +24,8 @@ pub trait Prettify: Send + Sync {
2424
self.name().to_lowercase().replace(" ", "_")
2525
}
2626

27-
fn syntax_highlight(&self) -> syntax_highlight::Language {
28-
syntax_highlight::Language::None
27+
fn syntax_highlight(&self) -> Language {
28+
Language::None
2929
}
3030

3131
fn prettify(&self, data: &[u8], metadata: &dyn Metadata) -> Result<String>;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use crate::contentviews::{Metadata, Prettify, Reencode};
2-
use crate::syntax_highlight::Language;
1+
use super::{Metadata, Prettify, Reencode};
2+
use mitmproxy_highlight::Language;
33
use anyhow::{Context, Result};
44
use rmp_serde::{decode, encode};
5-
use serde_yaml;
65

76
pub struct MsgPack;
87

@@ -41,7 +40,7 @@ impl Reencode for MsgPack {
4140
#[cfg(test)]
4241
mod tests {
4342
use super::*;
44-
use crate::contentviews::TestMetadata;
43+
use crate::TestMetadata;
4544

4645
// Hardcoded MsgPack data for a simple object:
4746
// {

0 commit comments

Comments
 (0)