httptoolkit / httptoolkit-server

The backend of HTTP Toolkit
https://httptoolkit.com
GNU Affero General Public License v3.0
447 stars 101 forks source link

How to configure mock requests without any browser interaction. #42

Closed vikasg603 closed 2 years ago

vikasg603 commented 2 years ago

Hey HTTP toolkit team, currently I am trying to set up some automation where I am interested to mock some requests and send that to my local server for some processing.

I can easily do this when I am on GUI but not able to figure it out the same when not using any browser but depends entirely on the terminal.

I also tried login my HTTP toolkit pro account but even this is not possible since your login server is checking the cookie and there's no way, I can provide any configurations to the HTTP toolkit server for things related to these.

Is there any way, i can configure login and mock requests using some JSON files?

pimterry commented 2 years ago

If you're trying to configure a totally headless HTTP proxy, I think you probably don't want to use this repo, you want to use Mockttp directly. That's the internals of HTTP Toolkit's HTTP proxy itself, as a standalone open-source library.

You can use that to define rules in code to mock responses or redirect traffic, with no UI required, and in real code so you can implement any kind of logic you like. There's a getting started guide here: https://httptoolkit.tech/blog/javascript-mitm-proxy-mockttp/.

Does that work for your use case? If not, can you explain a bit more about what you're trying to do?

vikasg603 commented 2 years ago

@pimterry definitely I was looking for something similar but this again creates some issues like how can I connect Mockttp to HTTP toolkit android application. With HTTP toolkit android app we can avoid installing system certificate and that's make our work easy.

pimterry commented 2 years ago

Ah ok, I see. I think Mockttp is still the way to go but you'll need some extra code to handle the Android setup, yes.

Can you share some more about what you're trying to do? What application are you intercepting and why, on what kinds of devices?

vikasg603 commented 2 years ago

I can't name the application but can explain what we are trying to achieve. Let's say the app name is X. In X when we create an account there we have some captcha verification and we are trying to automate the whole process using genymotion cloud + ubuntu. When I am using the HTTP toolkit locally I can redirect the captcha page to some local server where it will solve the captcha using 2captcha API and then will return a custom response, Which X will assume as a valid response and will allow me to register an account.

But the problem which I am facing currently

  1. HTTP toolkit pro is using the session to identify user login so need browser interaction for anything related to login.
  2. If using Mockttp, the android setup will be completely manual, which I want to avoid.
pimterry commented 2 years ago

I definitely think you don't want to use the HTTP Toolkit UI in this case - that's entirely designed for manual debugging etc, not automation. Even if you get it working now, it will definitely change in future in frequent and unpredictable ways that will break your setup.

I think you probably want to:

That should work, and work reliably because you'd have fixed dependencies through npm.

A couple of caveats:

vikasg603 commented 2 years ago

Hey, @pimterry thanks for the guide, I will definitely go through it, and about connecting ADB with graphql, I was actually having an API which I got using the same method you mentioned. I was only having an issue with connecting the HTTP toolkit with Mockttp, but with your guide, it will be easy for me to configure this. About the licensing part, I would love to make my code open source so that newcomers can understand it easily.