Add your own content view to mitmproxy

What is content view?

mitmproxy allows you to choose the format to display when displaying the contents of the request response.

image.png

The mechanism for displaying each format is called ** content view ** in mitmproxy.

Basic things such as html, css, json are prepared as standard.

Create your own content view

Since mimproxy can be extended with Python, you can also create your own ** content view **!

Examples in the official github repository So, let's take that code as an example.

An example of this is ** "Display the contents of the request / response in a different case" **.

custom_contentview.py


from mitmproxy import contentviews


# contentviews.Create a class that inherits View
class ViewSwapCase(contentviews.View):
    name = "swapcase"

    #Specify a shortcut key to apply this display when started with CUI
    prompt = ("swap case text", "z")

    content_types = ["text/plain"]

    #Put the main content rewriting process here
    # data:Contents of request / response
    # metadata: metadata["headers"]You can see the HTTP headers at
    def __call__(self, data, **metadata):
        return "case-swapped text", contentviews.format_text(data.swapcase())


view = ViewSwapCase()


def load(l):
    contentviews.add(view)


def done():
    contentviews.remove(view)

load and start

I couldn't read it well with my own mitmproxy as it is. As a result of looking at the source code of mitmproxy and doing various things, I succeeded in loading by changing def load (l) to def start ().

-def load(l):
+def start():
    contentviews.add(view)

Looking at mitmproxy's github, it seems that the version you are running is different because it was rewritten from start to load on the way.

addon loader: add boot_into, which replaces returning from start()

Start with the extension script installed

You can add the script file path by adding -s to the argument of the mitmproxy (or mitmweb, mitmdump) command.

I use mitmweb because I can't use mitmproxy in a Windows environment.

mitmweb -s custom_contentview.py

This is successful if ** swapcase ** is added to the request / response format selection.

image.png

Reference link

Overview — mitmproxy 2.0.2 documentation

Recommended Posts

Add your own content view to mitmproxy
Wagtail Recommendation (5) Let's add your own block to StreamField
How to create your own Transform
Bridge ROS to your own protocol
Add a GPIO board to your computer. (1)
Migrate your own CMS data to WordPress
To import your own module with jupyter
How to install your own (root) CA
[python] How to add RDF triples to your own Fuseki server using rdflib
Add your favorite display function to pip search
How to define your own target in Sage
Annotate your own data to train Mask R-CNN
Steps to install your own library with pip
Memo to create your own Box with Pepper's Python
[Introduction to Udemy Python 3 + Application] 66. Creating your own exceptions
Try to improve your own intro quiz in Python
Try to put LED in your own PC (slightly)
[Road to intermediate Python] Define in in your own class
Create your own exception
[Ansible] How to call variables when creating your own module
How to use pyenv and pyenv-virtualenv in your own way
(Note) How to pass the path of your own module
Use mitmproxy to force your app's API into your development environment
Try HeloWorld in your own language (with How to & code)