1
1
---
2
2
title : " Mitmproxy 12: Interactive Contentviews"
3
- date : 2025-04-22
3
+ date : 2025-04-29
4
4
weight : 10
5
5
tags :
6
6
- releases
@@ -26,7 +26,12 @@ Now, with interactive contentviews, you can directly edit the human-readable, pr
26
26
and mitmproxy will handle the task of re-encoding it back into its binary form.
27
27
This dramatically simplifies tinkering with unknown binary protocols such as gRPC/Protobuf or MsgPack.
28
28
29
- (protobuf gif)
29
+ <figure >
30
+ <video controls >
31
+ <source src="grpc.mp4" type="video/mp4">
32
+ </video >
33
+ <figcaption >Modifying a gRPC message on-the-fly (without knowing its schema).</figcaption >
34
+ </figure >
30
35
31
36
[ introduced in 2011 ] : https://github.com/mitmproxy/mitmproxy/commit/93ef691badcdaa1b7a5801eb40982c69f9b89534
32
37
[ #764 ] : https://github.com/mitmproxy/mitmproxy/pull/764
@@ -43,7 +48,9 @@ whether you have access to the Protobuf definitions (`.proto` files) or not.
43
48
- ** Unknown Protobufs:** You won't have field names, but you can still interactively modify primitive values
44
49
(strings, integers, nested messages) and mitmproxy will re-encode your changes.
45
50
46
- (screenshot of example gRPC with and without definitions)
51
+ {{< figure src="grpc.png"
52
+ alt="A screenshot of mitmproxy's gRPC rendering, both with and without protobuf definitions"
53
+ caption="gRPC with (left) and without (right) Protobuf definitions." >}}
47
54
48
55
[ `protobuf_definitions` ] : https://docs.mitmproxy.org/stable/concepts/options/#protobuf_definitions
49
56
@@ -52,27 +59,47 @@ whether you have access to the Protobuf definitions (`.proto` files) or not.
52
59
Underpinning this interactivity is a revamped and drastically simpler Contentview API.
53
60
Instead of returning a list of lines with inline markup,
54
61
the new [ ` prettify ` ] method simply takes ` bytes ` and returns ` str ` , and then [ ` reencode ` ] does the reverse.
55
- As a simple example, here's what mitmproxy's builtin contentview for DNS messages looks like :
62
+ As an example, here's a simple interactive contentview that dumps and parses data as hex :
56
63
57
- (DNS example snippet)
64
+ ``` python
65
+ from mitmproxy import contentviews
58
66
59
- Check out our [ new contentview documentation] for more examples!
67
+ class Hex (contentviews .InteractiveContentview ):
68
+ def prettify (
69
+ self ,
70
+ data : bytes ,
71
+ metadata : contentviews.Metadata
72
+ ) -> str :
73
+ return data.hex()
74
+
75
+ def reencode (
76
+ self ,
77
+ prettified : str ,
78
+ metadata : contentviews.Metadata
79
+ ) -> bytes :
80
+ return bytes .fromhex(prettified)
81
+
82
+ contentviews.add(Hex)
83
+ ```
84
+
85
+ Adding this to mitmproxy is as easy as ` mitmproxy -s example.py ` ,
86
+ please check out our [ new contentview documentation] for more examples!
60
87
61
88
[ `prettify` ] : https://docs.mitmproxy.org/stable/api/mitmproxy/contentviews.html#Contentview.prettify
62
89
[ `reencode` ] : https://docs.mitmproxy.org/stable/api/mitmproxy/contentviews.html#Contentview.reencode
63
90
[ new contentview documentation ] : https://docs.mitmproxy.org/stable/addons/contentviews/
64
91
65
- ## Rust-based Contentviews
92
+ ## Rust-based Contentviews 🦀
66
93
67
- With the new API, we're also increasing our investment in Rust to deliver safe and performant contentviews :
94
+ With the new Contentview API, we're also increasing our investment in Rust:
68
95
69
- - ** Built-in contentviews can now also be written in Rust.** In fact, the gRPC, Protobuf, and MsgPack contentviews
70
- are all Rust-based. The [ MsgPack implementation] is a great example to demonstrate how access to the crates.io
71
- ecosystem and the [ serde] framework in particular makes writing contentviews super easy.
72
- - ** Syntax highlighting is now done in Rust.** For mitmproxy and mitmweb, the [ mitmproxy-highlight] crate does all the
73
- work (using [ tree-sitter] under the hood).
96
+ - ** Contentviews can now be written in Rust.**
97
+ Access to the crates.io ecosystem (and [ Serde] in particular) makes it easy to write safe and performant
98
+ contentviews. In fact, the new gRPC, Protobuf, and MsgPack contentviews are all Rust-based.
99
+ - ** Syntax highlighting is now done centrally in Rust.** For mitmproxy and mitmweb, the [ mitmproxy-highlight] crate does
100
+ all the work (using [ tree-sitter] under the hood). Contentviews only need to declare their output format.
101
+ This is much more efficient than the previous implementation, where every contentview had to do highlighting itself.
74
102
75
- [ MsgPack implementation ] : https://github.com/mitmproxy/mitmproxy_rs/blob/5ec05682b122a2c1ee6584b4fe57a698eef573fd/mitmproxy-contentviews/src/msgpack.rs
76
- [ serde ] : https://serde.rs/
103
+ [ Serde ] : https://serde.rs/
77
104
[ mitmproxy-highlight ] : https://github.com/mitmproxy/mitmproxy_rs/tree/main/mitmproxy-highlight
78
105
[ tree-sitter ] : https://tree-sitter.github.io/tree-sitter/
0 commit comments