title: python selenium browsermob-proxy and interceptor
body: <p>I use python with selenium and browsermob-proxy.
  When action occurs ( click, submit), I wish to change http request url.
  I don't understand browsermob-proxy explanation:</p>
  
  <pre>
  
  request_interceptor(js)[source]
  Executes the java/js code against each response HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo are available objects to interact with. :param str js: the js/java code to execute
  </pre>
  
  <p><code></p>
  
  <pre><code> server = Server("C:\\browsermob-proxy-2.1.4\\bin\\browsermob-proxy.bat")
     server.start()
     proxy = server.create_proxy()
     request_js = " *** code *** "
     proxy.request_interceptor(request_js)
  </code></pre>
  
  <p></code></p>
  
  <p>how do I write code in "request_js" in order to change request url?
  Is it a possible example?</p>
  
  <p>How do I translate the code below in python?
  <code></p>
  
  <pre><code>proxy.addRequestFilter(new RequestFilter() {
              @Override
              public HttpResponse filterRequest(HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo) {
                  if (messageInfo.getOriginalUri().endsWith("/some-endpoint-to-intercept")) {
                      // retrieve the existing message contents as a String or, for binary contents, as a byte[]
                      String messageContents = contents.getTextContents();
  
                      // do some manipulation of the contents
                      String newContents = messageContents.replaceAll("original-string", "my-modified-string");
                      //[...]
  
                      // replace the existing content by calling setTextContents() or setBinaryContents()
                      contents.setTextContents(newContents);
                  }
  
                  // in the request filter, you can return an HttpResponse object to "short-circuit" the request
                  return null;
              }
          });
  </code></pre>
  
  <p></code></p>