11---
22title : " Mitmproxy 12: Interactive Contentviews"
3- date : 2025-04-22
3+ date : 2025-04-29
44weight : 10
55tags :
66 - releases
@@ -26,7 +26,12 @@ Now, with interactive contentviews, you can directly edit the human-readable, pr
2626and mitmproxy will handle the task of re-encoding it back into its binary form.
2727This dramatically simplifies tinkering with unknown binary protocols such as gRPC/Protobuf or MsgPack.
2828
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 >
3035
3136[ introduced in 2011 ] : https://github.com/mitmproxy/mitmproxy/commit/93ef691badcdaa1b7a5801eb40982c69f9b89534
3237[ #764 ] : https://github.com/mitmproxy/mitmproxy/pull/764
@@ -43,7 +48,9 @@ whether you have access to the Protobuf definitions (`.proto` files) or not.
4348- ** Unknown Protobufs:** You won't have field names, but you can still interactively modify primitive values
4449 (strings, integers, nested messages) and mitmproxy will re-encode your changes.
4550
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." >}}
4754
4855[ `protobuf_definitions` ] : https://docs.mitmproxy.org/stable/concepts/options/#protobuf_definitions
4956
@@ -52,27 +59,47 @@ whether you have access to the Protobuf definitions (`.proto` files) or not.
5259Underpinning this interactivity is a revamped and drastically simpler Contentview API.
5360Instead of returning a list of lines with inline markup,
5461the 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 :
5663
57- (DNS example snippet)
64+ ``` python
65+ from mitmproxy import contentviews
5866
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!
6087
6188[ `prettify` ] : https://docs.mitmproxy.org/stable/api/mitmproxy/contentviews.html#Contentview.prettify
6289[ `reencode` ] : https://docs.mitmproxy.org/stable/api/mitmproxy/contentviews.html#Contentview.reencode
6390[ new contentview documentation ] : https://docs.mitmproxy.org/stable/addons/contentviews/
6491
65- ## Rust-based Contentviews
92+ ## Rust-based Contentviews 🦀
6693
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:
6895
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. 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.
74102
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/
77104[ mitmproxy-highlight ] : https://github.com/mitmproxy/mitmproxy_rs/tree/main/mitmproxy-highlight
78105[ tree-sitter ] : https://tree-sitter.github.io/tree-sitter/
0 commit comments