There are some tools like proxychain-ng which support composing proxies in this way, but the way they do that is subtly different than what I think needs to be done here.
One way to compose proxies (for security/privacy, e.g. "I'm behind 7 proxies") is to chain the proxies against each other so they relay end to end. P1 forms a tunnel with P2, with forms a tunnel with P3, then packets go from p1 -> p2 -> p3. In terms of implementation, this is only possible if the proxy supports establishing a blind tunnel (e.g. HTTP CONNECT) as otherwise there is no way to establish a forwarding tunnel.
The normal HTTP GET proxy protocol always specifies the destination and resource in-band, which causes an issue. If the client tries to send to P1
Code:
GET http://p2-addr/http://macrumors.com HTTP/1.1
then P1 will send to P2
Code:
GET /https://www.macrumors.com HTTP/1.1
which is unfortunately invalid (note the leading slash).
SOCKS proxies also support tunnel, so you can chain those. And I think you can also chain an HTTP CONNECT proxy to a socks proxy or vice-versa (assuming your http proxy doesn't restrict the tunnel to port 443 and 80).
Proxychains and other software can support stuff like this, but they all assume blind forwarding proxies whereas aquaproxy needs to actually inspect and MITM the traffic. So if you want to support generic chaining in this fashion, it needs to be updated to track the outgoing hops on your behalf. This is probably overkill though [^1] compared to just adding an option to have aquaproxy route outgoing requests through another proxy.
[^1] In the "simple" case of chaining HTTP proxies, it needs to handle nested HTTP connect. Currently
it assumes that after receiving a HTTP CONNECT the client will perform a TLS handshake, it is not expecting client to send another HTTP CONNECT. (probably if you try it as is, it will error out or something since it's an invalid TLS hello). You'd need to identify these and "pass along" all HTTP connects (since the chain can have many hops). The TLS interception should work as-is though, since eventually when the client has established all the CONNECTS it will send a TLS hello, and that can be intercepted and MITM'd as before.
This gets even more complicated for the case of chaining to a socks proxy, since SOCKS is a lower level protocol and the TLS hello will be wrapped in the SOCKS header. So you'd need to implement your own split logic for that. I see there are some
tools that can provide an HTTP proxy front for a SOCKS proxy though so if you use that then everything behaves as before. And conceptually it's not too hard to front a SOCKS proxy with an HTTP connect protocol.
All that to say, either aquaproxy just adds a flag for making outgoing connections using a proxy, or you nuke the mosquito by implementing general HTTP proxy chaining support, combine that with proxychains + a http proxy frontend for socks.