Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Network throttling in iOS app programatically for automation. #59

Open
amit1990sumit opened this issue Jun 14, 2018 · 11 comments
Open

Network throttling in iOS app programatically for automation. #59

amit1990sumit opened this issue Jun 14, 2018 · 11 comments
Labels

Comments

@amit1990sumit
Copy link

Hi Team,

Is it possible that I can throttle network on my iOS app or specific URL?
Please help me to understand this, what are the things required for this if possible.

Thanks

@h2non
Copy link
Owner

h2non commented Jun 14, 2018

Yes, as long as you put toxy in the middle of the communication:

iOS --> toxy proxy --> target server

Your iOS should communicate with the toxy proxy directly and there is where the throttling would happen.

@h2non h2non added the question label Jun 14, 2018
@amit1990sumit
Copy link
Author

amit1990sumit commented Jun 14, 2018

Thanks for reply. Since I am new to node js, could you please guide me how to hit api to localhost using node js?

Thanks again

@h2non
Copy link
Owner

h2non commented Jun 14, 2018

See some examples, such as: https://github.com/h2non/toxy/blob/master/examples/bandwidth-limit.js

Run it locally from the console via: $ node example.js

You need to replace the httpbin.org domain with the server you want to consume. Afterwards, you need to consume the toxy server running in localhost in your iOS app. Assuming you can't consume it via local IP address/hostname in your LAN, you can use this node.js package to create a tunnel in order to expose the toxy server to the Internet, and consume from everywhere, including your iOS app:

$ npm install -g localtunnel

Then:

$ lt --port 3000 --subdomain my-toxy-proxy-server

That would give you an URL like: https://my-toxy-proxy-server.localtunnel.me that you can use in your iOS app.

That's all. Enjoy it.

@amit1990sumit
Copy link
Author

Thank you so much for ur reply.
One last question, can I add proxy ip and port inside iphone proxy setting so that we can track all the network call which go through iphone. I want same as charles proxy, only thing it should be programmatically.
Please help me.

@h2non
Copy link
Owner

h2non commented Jun 16, 2018

As far as I know, you don't need to explicitly use the "proxy" mode in the iPhone. You just need to communicate to the target IP/hostname of toxy, and then you can programmatically inspect, log, modify the incoming HTTP traffic from the phone. You can see the middleware/intercept/logging examples.

@amit1990sumit
Copy link
Author

Ok, but i do not want to proxy specific url, In my case, my framework itself hit all the network call and i am unable to access the urls. I want to add proxy so that any network call able to track which go through my iphone.

Please help and thank you again

@amit1990sumit
Copy link
Author

Today, I tried all the steps what you mentioned,

  1. I create the tunnel and run "lt --port 3000 --subdomain my-toxy-proxy-server" which gave URL = "https://my-toxy-proxy-server.localtunnel.me"
  2. Replaced the same URL in example project "bandwidth-limit.js".
  3. run the "bandwidth-limit.js" which gives "Server listening on port: 3000".

but found that no call goes through a proxy.

Currently, I am trying this in a browser. Please let me know if anything missing from my end. Please help me.

@h2non
Copy link
Owner

h2non commented Jun 17, 2018

This looks like an XY problem. I'm not actually sure that you know what you want or you actually understand how the network works. Please, make sure you understand these things. Otherwise I can't help.

@amit1990sumit
Copy link
Author

Thanks for reply and sorry to bother you.
Actually I am new to server side script and most of the thing I undertood now.
Only prob I am facing now, In readme file there are serveral API mentioned.

API
Hierarchy:

Servers - Managed toxy instances
Rules - Globally applied rules
Poisons - Globally applied poisons
Rules - Poison-specific rules
Routes - List of configured routes
Route - Object for each specific route
Rules - Route-level registered rules
Poisons - Route-level registered poisons
Rules - Route-level poison-specific rules
GET /
Servers
GET /servers
GET /servers/:id
Rules
GET /servers/:id/rules
POST /servers/:id/rules
Accepts: application/json

Example payload:

{
  "name": "method",
  "options": "GET"
}

Just want to know how I can access these API from client end.

@h2non
Copy link
Owner

h2non commented Jun 17, 2018

You can take a look at the instructions on the Readme > Admin API section. Basically, you need to start 2 HTTP servers running on different ports, one for the proxy itself, and another for the HTTP Admin API. You can see an example as well on the repository. Note that this is apposite to your initial intention about having programmatic control of the proxy.

@amit1990sumit
Copy link
Author

amit1990sumit commented Jun 17, 2018

Thanks for the reply.

I think HTTP API is the only way to achieve throttled at runtime from the iOS app otherwise no other way to access proxy rules and poison.

I run admin server on port 9000 and proxy server in 3000 port.
Now, I hit my media URL using "http://localhost:3000/iphone/samples/bipbop/bipbopall.m3u8" and I start playing the video then I am setting poison and rules using HTTP API given below.
POST: http://localhost:9001/servers/8dd/poisons
{
"name": "inject",
"option": {
"code": 404,
"body": {"error": "toxy injected error"},
"headers": {"Content-Type": "application/json"}
},
"probability": 100
}
And I am able to generate an error in between and player through error.

Now the only issue, when I hit HTTP API to limit bandwidth, it is not setting the actual bandwidth what I am passing to in json request mentioned below.
Using: POST http://localhost:9000/servers/8dd/poisons (I am using the simulator for now)
{
"name": "bandwidth",
"phase": "outgoing",
"options": { "bps": 512000}
}

Thanks again for helping me throughout.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants