webmetrics / browsermob-proxy

NOTICE: this project has been forked and is being maintained at https://github.com/lightbody/browsermob-proxy
https://github.com/lightbody/browsermob-proxy
Apache License 2.0
234 stars 772 forks source link

HTTP Request Manipulation via REST API #57

Open j1n6 opened 12 years ago

j1n6 commented 12 years ago

What's the timeline for this http request manipulation Rest API?

Note: I am looking for the feature of manipulating HTTP response body before a page renders in browsers.

airduster commented 12 years ago

Think this is already allowed. via the addRequestInterceptor() method which allows you to pass in your own HttpRequestInterceptor (from the apache HttpClient project: org.apache.http.HttpRequestInterceptor). Exposing this object allows you to manipulate every request or response body's Http headers. You can even get the entity's content via the response object.

Example:

ProxyServer proxyServer = new ProxyServer(9101); proxyServer.start();

proxyServer.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { //request.removeHeaders("User-Agent"); //request.addHeader("User-Agent", "Bananabot/1.0"); Header[] headers = request.getAllHeaders(); System.out.println("\nRequest Headers\n\n"); for(Header h : headers) { System.out.println("Key: " + h.getName() + " | Value: " + h.getValue()); }

        }
    });

public void process(HttpResponse response, HttpContext context)throws org.apache.http.HttpException, IOException { Header[] headers = response.getAllHeaders(); System.out.println("\nResponse Headers\n\n"); for(Header h : headers) { System.out.println("Key: " + h.getName() + " | Value: " + h.getValue()); }

            //new BufferedHttpEntity(response.getEntity())
            // do stuff with response.getEntity().getContent();
        }
    });
j1n6 commented 12 years ago

Just updated the request title, I was asking about replacing content through "Rest API", not Java API