Simplify Proxy + iOS configuration

Sergey Yamshchikov
2 min readJan 8, 2021

There is always a point when we, as mobile devs, have to debug how our apps communicate through Network. Cool part is that the Market full of different solutions for that. But one thing is still annoying: configuration.

Problems

  1. Turn on and turn off proxy configuration on iOS
  2. iOS simulator requires us to configure proxy for the Mac OS itself

But we can simplify it

  1. Automate proxy configuration

We can leverage power of Auto-Proxy for that. It gives us 2 cool feature:

  • Configurable proxy host
  • If proxy is not available we can send the traffic directly to the network

For instance, if configure auto-proxy on a device to fetch configuration from our server which respond with:

function FindProxyForURL(url, host)
{
return "PROXY localhost:8080; DIRECT";
}

All our traffic will go through localhost proxy, if it’s available, and directly to target server if it’s not. Hence no need to change your configuration each time.

Only one bottle neck here. Configuring server on your laptop is not hard, but tedious and not flexible.

Fortunately with help of small python package name pyautoproxy we can do that just in few commands (For sure you need Python3 installed on your machine, or you can try to use the same, almost the same, thing written in Swift).

Let’s got through:

Install pyautoproxy :

pip install pyautoproxy

Run:

pyautoproxy -p 8081

This command will start the server on localhost:8081 .

Configure Mac OS:

SystemPreferences -> Network -> Advanced -> Proxies -> Automatic Proxy Configuration

There is only one field to be filled: URL for Proxy Configuration File. We just need to put URL to our pyautoproxy instance and there is a cool part, we can configure the response by passing query parameters to our pyautoproxy e.g.

http://localhost:8081?host=localhost&port=8080// host - proxy host
// port - proxy port
// With the line above, the answer will looks like thisfunction FindProxyForURL(url, host)
{
return "PROXY localhost:8080; DIRECT";
}
// If we change host or porthttp://localhost:8081?host=127.0.0.1&port=1111// The answer will befunction FindProxyForURL(url, host)
{
return "PROXY 127.0.0.1:1111; DIRECT";
}

Apply the configuration and from now, once you start your Proxy on localhost:8080 your Mac OS will automatically pass all the traffic through it. And automatically stop doing it once the Proxy is not available anymore.

You can easily do the same on any iOS device within Network settings.

2. Filter iOS Simulator traffic

I was doing a lot of Network debugging with iOS for last year, and one of the most annoying problem is that you can’t easily find which request comes from Mac OS and which from the Simulator, it happens because the Simulator use the same interface, but fortunately it requests the proxy configuration on it’s own. And we can use it.

Just run pyautoproxy with -s parameter, and it will automatically send Proxy configuration exclusively to the Simulator and keep Mac OS away from the Proxy

pyautoproxy -s -port 8081

Happy debugging ;)

--

--