browserup / browserup-proxy

BrowserUp Proxy is a free utility to watch, test, and manipulate web application network traffic and performance.
https://browserup.com
Apache License 2.0
164 stars 41 forks source link

Can't start proxy on custom port with java tools like RestAssured and Java 11 HTTP Client #277

Closed weendigo closed 4 years ago

weendigo commented 4 years ago

Describe the bug We are automating multiple proxies initialization on custom ports using REST Assured (or and Java 11 HTTP client). Attempts to start proxy on custom port with POST calls using the aforementioned tools end up with proxy starting but not on specified port.

Code for REST Assured:

        String body = "port:"+ port;
        //String body = "{\"port\":\""+ port +"\"}";

        var response = given()
        .body(body)
        .log().all()
        .when()
        .post(proxyAddress)
        .then().log().all();

Code for Java HTTP client:

        String body = "port:"+ port;
        //String body = "{\"port\":\""+ port +"\"}";
        System.out.println(body);
        HttpClient client = HttpClient.newHttpClient();

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(proxyAddress))
                .timeout(Duration.ofMinutes(1))
                .header("Content-Type", "text/plain")
                .POST(BodyPublishers.ofString(body))
                .build();

        client.sendAsync(request, BodyHandlers.ofString())
                .thenApply(HttpResponse::body)
                .thenAccept(System.out::println).join();

To Reproduce Steps to reproduce the behavior:

  1. Start BUP instance
  2. Send a POST call using the code examples above
  3. Proxy is started but on default port, e.g. response reads { "port": 8082 }
  4. Same behavior is reproducible with text and JSON-formatted payload.

REST Assured logs: Example of request:

Request method: POST
Request URI:    http://localhost:8080/proxy/
Proxy:          <none>
Request params: <none>
Query params:   <none>
Form params:    <none>
Path params:    <none>
Headers:        Accept=*/*
                Content-Type=text/plain; charset=ISO-8859-1
Cookies:        <none>
Multiparts:     <none>
Body:
port:11001

Respective response:

HTTP/1.1 200 OK
Date: Thu, 11 Jun 2020 10:19:29 GMT
Content-Type: application/json
Content-Length: 13
Server: Jetty(9.4.20.v20190813)
{
    "port": 8089
}

Java client log:

[port:11001
{"port":8088}]

Expected behavior Proxy should be started on the specified port.

Please complete the following information:

Additional context Using curl for starting the proxy seems to work fine however we couldn't figure out how to incorporate this in our workflow or how to emulate it in Java.

Other POST call using REST Assured works fine - specifically, we are sending JSON-formatted hosts entries to http://(address}:8080/proxy/{port}/hosts and that is without problem.

weendigo commented 4 years ago

Oh crap, is this a dupe of #245?

ericbeland commented 4 years ago

Closing as dup.