Intercept and filter HTTP request

filter, http, https, java, sniffer

Solution

Have you tried Servlet Filters?

They wrap the HTTP request and so can modify the request before it gets to the servlet, and can modify the response as well. They can (and are) used to wrap third-party servlets and JSPs.

Because they are in the servlet container, you have secure, unencrypted access to both the request and response.

Problem

I want to intercept/sniff incoming HTTP request and filter/modify their contents (before they reach the application). "Fiddler" seems to have this functionality, but for the sake of integration and portability I would rather have some library in Java/C to do this. Like JPCAP, for example. It intercepts IP packets, but, as stated, I need to intercept the -higher level- HTTP requests. Furthermore, how can SSL encrypted (HTTPS) requests be read/modified in the same way? Thanks in advance.

Original source