Giter Site home page Giter Site logo

dev-segal / mitmproxy-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from appium/mitmproxy-java

0.0 1.0 0.0 117 KB

A bridge between Python's mitmproxy and Java programs. Built on top of mitmproxy-node

License: Apache License 2.0

Python 38.69% Java 61.31%

mitmproxy-java's Introduction

Java rendition of node-mitmproxy

Make sure to read the prerequisites section below.

Detailed information included in the AppiumPro article which introduces this library.

Why?

mitmproxy is great for capturing network traffic, but has no easy interface for Java users. The software testing community, specifically Appium mobile testers, want to be able to capture network requests made by devices during their Java tests.

This library will run mitmproxy in the background as a separate process, and allow you to pass in a lambda function which gets called on every network request captured by mitmproxy. This allows you to check the captured requests within you Java code without having to stop the proxy or end capture.

See @jonahss's Appium Pro posts on this topic:

What can I use this for?

For transparently rewriting HTTP/HTTPS responses. The mitmproxy plugin lets every HTTP request go through to the server uninhibited, and then passes it to Java via a WebSocket for rewriting.

How does it work?

mitmproxy-java starts a Websocket server and a Python plugin for mitmproxy connects to it and sends requests over. The two communicate via binary messages to reduce marshaling-related overhead.

Pre-requisites

  • mitmproxy V4 must be installed and runnable from the terminal. The install method cannot be a prebuilt binary or homebrew, since those packages are missing the Python websockets module. Install via pip or from source.
  • Python 3.6, since we use the new async/await syntax in the mitmproxy plugin
  • pip3 install websockets

Maven:

<dependency>
  <groupId>io.appium</groupId>
  <artifactId>mitmproxy-java</artifactId>
  <version>1.6.2</version>
</dependency>

Gradle:

testCompile group: 'io.appium', name: 'mitmproxy-java', version: '1.6.1'

Usage

List<InterceptedMessage> messages = new ArrayList<InterceptedMessage>();

//optional, default port is 8080
int mitmproxyPort = 8090;

//optional, you can pass null if no extra params
List<String> extraMitmproxyParams = Arrays.asList("param1", "value1", "param2", "value2");

// remember to set local OS proxy settings in the Network Preferences
proxy = new MitmproxyJava("/usr/local/bin/mitmdump", (InterceptedMessage m) -> {
    System.out.println("intercepted request for " + m.getRequest().getUrl());
    messages.add(m);
    return m;
}, mitmproxyPort, extraMitmproxyParams);

proxy.start();

// do stuff

proxy.stop();

See AppriumPro article for more guidelines: https://appiumpro.com/editions/65 Example can be found here: https://github.com/cloudgrey-io/appiumpro/blob/master/java/src/test/java/Edition065_Capture_Network_Requests.java

Your Java code is bad and you should feel bad

I'm no Java expert! You may see some bad patterns, like my terrible disregard for exception handling. Let's make it better. File your issues and land some PRs! I wrote this in just a couple days for our weekly newsletter.

Your Python plugin is bad and you should feel bad

See node-mitmproxy. Pull requests welcome!

Develop

Upload to Central Repository with command ./gradlew uploadArchives

mitmproxy-java's People

Contributors

czolg avatar jonahss avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.