Open j1n6 opened 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();
}
});
Just updated the request title, I was asking about replacing content through "Rest API", not Java API
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.