Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Request Manipulation via REST API #57

Open
j1n6 opened this issue Jun 15, 2012 · 2 comments
Open

HTTP Request Manipulation via REST API #57

j1n6 opened this issue Jun 15, 2012 · 2 comments

Comments

@j1n6
Copy link

j1n6 commented Jun 15, 2012

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
Copy link

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
Copy link
Author

j1n6 commented Aug 16, 2012

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

nirvdrum pushed a commit to mogotest/browsermob-proxy that referenced this issue Mar 26, 2014
…hantom-js-fetcher

Improved auto-fetch of PhantomJS if absent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants