Custom header customization using BrowserMob-Proxy REST api

I have a browsermob proxy running on port 9091. I am trying to use the Rover API of the browser browser to set a custom header. When I make a request to my application using Selenium through a proxy server, I do not see the header printed in the application console. Below is my code. The request body is based on the documentation here . My requirement is to use the BrowserMob proxy server and not its Java library for this particular use case. Anything I'm doing wrong in the code below?

 Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("localhost", 9091));

 String bpmUrl = "http://localhost:8787/proxy/9091/interceptor/request";
 Client client = Client.create();
 String requestBody = "request.getMethod().addHeader(\"custom-header\", \"Bananabot/1.0\");";
 WebResource resource = client.resource(bpmUrl);
 resource.type(MediaType.TEXT_PLAIN_TYPE).post(requestBody);

 String url = "http://localhost:8004";
 DesiredCapabilities capabilities = DesiredCapabilities.firefox();
 capabilities.setCapability(CapabilityType.PROXY, proxy);
 WebDriver driver = new FirefoxDriver(capabilities);
 driver.get(url);
 driver.quit();

Change 1

I tried @Erki's solution, which I think should work, but it doesn't. Is something missing here?

 String bpmUrl = "http://localhost:8787/proxy/9091/headers";
     Map<String,String> data = new HashMap<String, String>();
     data.put("user-agent","Bananabot");
     ClientConfig cc = new DefaultClientConfig();
     cc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
     Client client = Client.create(cc);
     WebResource resource = client.resource(bpmUrl);
     resource.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, data);

2 , Java API, , -, . , , . java.net.Proxy org.openqa.selenium.Proxy, . , , , , -, . .

 String PROXY = "localhost:9091";
 Proxy proxy = new Proxy();
 proxy.setHttpProxy(PROXY);
+3
1

, BMP :

server.addRequestInterceptor(new RequestInterceptor() {
    @Override
    public void process(BrowserMobHttpRequest request, Har har) {
        request.getMethod().removeHeaders("User-Agent");
        request.getMethod().addHeader("User-Agent", "Bananabot/1.0");
    }
});

, - , , , , . , :

POST/proxy/[port]/headers - HTTP-. , . json ( URL)

+3

Source: https://habr.com/ru/post/1625913/


All Articles