I do not know what the proper name is for such proxy server, you're welcome to fix my question title.
When I search proxy server on google, a lot implements like maproxy or a-python-proxy-in-less-than-100-lines-of-code. Those proxies server seems just ask remote server to get a certain url address.
I want to build a proxy server, which contains a proxy pool(a list of http/https proxies) and only have one IP address and one port to serve incoming requests. When a request comes, it would choose a proxy from the pool and do this request, and return result back.
For example I have a VPS which IP '192.168.1.66'. I start proxy server at this VPS with IP '127.0.0.1' and port '8080'.
I can then use this proxy like below.
import requests
url = 'http://www.google.com'
headers = {
...
}
proxies = {
'http': 'http://192.168.1.66:8080'
}
r = requests.get(url, headers=headers, proxies=proxies)
I have see some impelement like:
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()
It works, but it is so simple that I have no idea how it works and how to improve this code to use a proxy pool.
An example flow :
from hidu/proxy-manager , which write by golang .
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ client (want visit http://www.baidu.com/) +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| via proxy 127.0.0.1:8090
|
V
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ + proxy pool +
+ proxy manager listen ++++++++++++++++++++++++++++++++++
+ on (127.0.0.1:8090) + http_proxy1,http_proxy2, +
+ + socks5_proxy1,socks5_proxy2 +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| choose one proxy visit
| www.baidu.com
|
V
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ site:www.baidu.com +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++