Skip to content

Maven, MitmProxy version 9: AttributeError: module 'mitmproxy.http' has no attribute 'HTTPResponse' #20

Closed
@bp32891

Description

@bp32891

Hello,

I recently started a Maven project using mitmproxy-java. Anytime I try to change the status code of an intercepted call, I get this error: AttributeError: module 'mitmproxy.http' has no attribute 'HTTPResponse'

`List messages = new ArrayList<>();

    MitmproxyJava proxy = new MitmproxyJava("/Library/Frameworks/Python.framework/Versions/3.10/bin/mitmdump", (InterceptedMessage m) -> {
        messages.add(m);
        m.getResponse().setBody("Hi from Test".getBytes(StandardCharsets.UTF_8));
        m.getResponse().getHeaders().add(new String[]{"myTestResponseHeader", "myTestResponseHeaderValue"});
        m.getResponse().setStatusCode(500);
        return m;
    });
    proxy.start();

    Unirest.setProxy(new HttpHost("localhost", 8080));
    HttpResponse<String> response = Unirest.get("http://appium.io").asString();

    driver.get("http://appium.io");

    System.out.println("RESPONSE");
    System.out.println(messages.get(0));

    TimeUnit.SECONDS.sleep(15);

    proxy.stop();

    assertThat(response.getBody()).isEqualTo("Hi from Test");

    final InterceptedMessage firstMessage = messages.get(0);

    assertThat(firstMessage.getRequest().getUrl()).startsWith("http://appium.io/");
    assertThat(firstMessage.getRequest().getHeaders()).containsOnlyOnce(new String[]{"myTestHeader", "myTestValue"});
    assertThat(firstMessage.getResponse().getHeaders()).containsOnlyOnce(new String[]{"myTestResponseHeader", "myTestResponseHeaderValue"});
    System.out.println(firstMessage.getResponse().getStatusCode());
    assertThat(firstMessage.getResponse().getStatusCode()).isEqualTo(500);`

I see that the newest version is 2.0.2 and I'm hoping it has the fix. But currently only 2.0.1 is available on Maven to insert into the POM file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions