Skip to content

Commit

Permalink
Merge pull request #18 from himanshunikhare25/master
Browse files Browse the repository at this point in the history
Added fix for proxy to run properly in mac environment
  • Loading branch information
Jonahss authored Mar 13, 2023
2 parents 8699e9c + 23d7034 commit e4fa7fd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ For transparently rewriting HTTP/HTTPS responses. The mitmproxy plugin lets ever

## Pre-requisites

* [`mitmproxy` V4](https://mitmproxy.org/) 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
* [`mitmproxy` V9](https://mitmproxy.org/) 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 and above, 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>
<version>2.0.2</version>
</dependency>
```

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

## Usage
Expand All @@ -67,10 +67,16 @@ proxy.start();
// do stuff

proxy.stop();
```

If the above code doesn't work, and you are getting
`Error=2, No such file or directory` please re-check your mitmdump path in new MitmproxyJava initialization.
You can get mitmdump path using below command:
```shell
whereis mitmdump
```

See AppriumPro article for more guidelines: https://appiumpro.com/editions/65
See AppiumPro 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
Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ plugins {
}

group = 'io.appium'
version = '2.0.1'
version = '2.0.2'
archivesBaseName = 'mitmproxy-java'

sourceCompatibility = 1.8

repositories {
mavenCentral()
jcenter()
}

dependencies {
Expand Down Expand Up @@ -46,7 +45,10 @@ artifacts {
archives javadocJar, sourcesJar
}
signing {
sign configurations.archives
setRequired {
// signing is only required if the artifacts are to be published
sign configurations.archives
}
}


Expand All @@ -60,10 +62,10 @@ uploadArchives {

// Destination
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
authentication(userName: hasProperty('ossrhUsername'), password: hasProperty('ossrhPassword'))
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
authentication(userName: hasProperty('ossrhUsername'), password: hasProperty('ossrhPassword'))
}

// Add required metadata to POM
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/scripts/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def request(self, flow):
new_metadata = message_response[0]
new_body = message_response[1]

flow.response = http.HTTPResponse.make(
flow.response = http.Response.make(
new_metadata['status_code'],
new_body,
map(convert_headers_to_bytes, new_metadata['headers'])
Expand Down Expand Up @@ -198,7 +198,7 @@ def response(self, flow):

#print("Prepping response!")

flow.response = http.HTTPResponse.make(
flow.response = http.Response.make(
new_metadata['status_code'],
new_body,
map(convert_headers_to_bytes, new_metadata['headers'])
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/io/appium/mitmproxy/MitmproxyJavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
public class MitmproxyJavaTest {

//private static final String MITMDUMP_PATH = "C:\\Python37\\Scripts\\mitmdump.exe";
private static final String MITMDUMP_PATH = "/usr/local/bin/mitmdump";
private static final String MITMDUMP_PATH = getMITMDumpPath();

static String getMITMDumpPath(){
if(System.getProperty("os.name").contains("Mac")){
return "/opt/homebrew/bin/mitmdump";
}
return "/usr/local/bin/mitmdump";
}
@Test
public void ConstructorTest() throws InterruptedException, IOException, TimeoutException {
MitmproxyJava proxy = new MitmproxyJava(MITMDUMP_PATH, (InterceptedMessage m) -> {
Expand Down

0 comments on commit e4fa7fd

Please sign in to comment.