Python twisted proxyclient cascade / upstream to squid

I would like to run a small http proxy on my computer, which sends all requests to an upstream / cascading proxy.

Twisted Web HTTP Proxy -> Squid -> Internet Connection

Unfortunately, I cannot figure out how to send all ProxyClient requests up / cascade them in Squid. Could you give me a hint?

Should I use .connectTCP and HttpClientFactory reactor for this and somehow redirect Squid response through?

I used the following twisted code example to get a twisted HTTP proxy:

from twisted.web import proxy, http from twisted.internet import reactor from twisted.python import log import sys log.startLogging(sys.stdout) class ProxyFactory(http.HTTPFactory): protocol = proxy.Proxy reactor.listenTCP(8080, ProxyFactory()) reactor.run() 

Thanks,

Matthias

+4
source share
2 answers

I think you complicate things too much. For me, it looks like what you want to do is a circular HTTP proxy load request between two squid services.

If it were me, I would not have written a byte of code or used something off the shelf.

I would use HA-Proxy with a configuration something like this:

 global daemon maxconn 256 defaults mode http timeout connect 5000ms timeout client 50000ms timeout server 50000ms frontend loadbal bind *:3128 default_backend squids option http_proxy backend squids option http_proxy server squid1 192.168.1.2:3128 server squid2 192.168.1.3:3128 balance roundrobin 

You may need to play a little, some web services may require certain types of stickiness, but this application is very customizable in this regard. HA-Proxy v 1.4 seems to support supported connections, which may simplify some of the corner cases I can imagine.

Oh, also, if you are trying to get the most out of your two connections, I would suggest setting up ICP between your two squid squares.

+1
source

It looks like something twisted.web.proxy.ReverseProxyResource might be helpful.

-1
source

Source: https://habr.com/ru/post/1334953/


All Articles