chhsiao90 / nitmproxy

Proxy server based on netty
MIT License
151 stars 67 forks source link

How to intercept the http response from server and modify it's content before sending it to the client? #86

Open abdou4a opened 3 years ago

abdou4a commented 3 years ago

I found this library and seemed to work on my case, but I am stuck finding a way to intercept the http response from server and modify it's content before sending it to the client.

abbasvalliani commented 3 years ago

I believe there are examples in the test cases. I am using this extensively. Where is the issue?

abdou4a commented 3 years ago

I am new to netty.io framework.... All I want is to create an http proxy server that performs MITM by modifying http response body from the server (backend) on the fly before hitting the client (frontend). After digging into the code of this library, I found this method could be the place to modify http response body. but I don't know how to parse the ByteBuf data (method parameter) to get plain (text/json) data from it.

I believe there are examples in the test cases

Could you point out to which example?

abbasvalliani commented 3 years ago

This may help.

https://github.com/chhsiao90/nitmproxy-examples/blob/master/src/main/java/com/github/chhsiao90/nitmproxy/examples/HttpInterceptor.java

abbasvalliani commented 2 years ago

@abdou4a You were right that this is indeed missing. The listener interface exists but is never called by the Http2EventHandler.

abbasvalliani commented 2 years ago

This may help.

https://github.com/chhsiao90/nitmproxy-examples/blob/master/src/main/java/com/github/chhsiao90/nitmproxy/examples/HttpInterceptor.java

This only works to create a whole new response.