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

Unable to modify response #108

Open
abbasvalliani opened this issue Oct 14, 2021 · 6 comments
Open

Unable to modify response #108

abbasvalliani opened this issue Oct 14, 2021 · 6 comments

Comments

@abbasvalliani
Copy link
Contributor

@chhsiao90 I don't believe there is call made in Http2EventHandler to modify the response data? For e.g. adding javascript injection to a response etc.

It would be great if we can modify the response object using the listener interface.

@abbasvalliani
Copy link
Contributor Author

abbasvalliani commented Oct 17, 2021

@chhsiao90 Do you want me to implement this feature or may be easier for you to do it? Quite urgent for me at the moment and happy to develop this if needed. We need to do this for both Http1 and Http2 as well as WebSockets. But Http1 and Http2 is critical for now.

@chhsiao90
Copy link
Owner

Hi @abbasvalliani

I commit a change to allow http2 response interception in fc4abec. With the update, it's possible to intercept the response data with current implementation by rewriting the ByteBuf of the http2 data frame.

It's not the most straightforward way to intercept data. The most straightforward way is to intercept the full response, and return another full response, ex: a method like FullResopnse intercept(FullResponse response), but I wold not prefer in this way as it will have significant performance impact to nitmproxy.

So I would prefer to provide some helper interceptors to simplify the process of interception based on current implementation.

I will have some draft by this week.

@abbasvalliani
Copy link
Contributor Author

@chhsiao90 I completely agree. One amazing part of NITM is how fast it is and we shouldn't compromise it. My use case and I am assuming most use cases would include intercepting Content-Type of HTML and replacing it with their own content. If the helper can provide interception with the header being available, that would be fantastic and potentially even a better helper to just intercept by Content-Type with the HTML content-type made easily available.

@chhsiao90
Copy link
Owner

May I know how do you plan to inject javascript inside a HTML page? Append the script to the end of html? Find specific tag and replace? It will help me to decide how to implement the API.

@abbasvalliani
Copy link
Contributor Author

More likely will be appended to the script tag at the end of the file.

@abbasvalliani
Copy link
Contributor Author

@chhsiao90 Changes look good. Can we push a release if possible? Thanks!

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