Add headers support
This commit is contained in:
parent
8ad46c0481
commit
71d9e18eec
1 changed files with 5 additions and 2 deletions
|
@ -21,7 +21,7 @@ class TorInstance():
|
|||
TOR_RUNNER = 0
|
||||
|
||||
@classmethod
|
||||
async def create(cls, history):
|
||||
async def create(cls, history, headers):
|
||||
""" Factory creation of tor processes"""
|
||||
socks_port = cls.BASE_SOCKS_PORT + cls.TOR_RUNNER
|
||||
control_port = cls.BASE_CONTROL_PORT + cls.TOR_RUNNER
|
||||
|
@ -32,6 +32,7 @@ class TorInstance():
|
|||
self.control_port = control_port
|
||||
self.data_dir = data_dir
|
||||
self.history = history
|
||||
self.headers = headers
|
||||
self.proxy = "socks5://127.0.0.1:{}".format(self.socks_port)
|
||||
self.create_session()
|
||||
self.process = tor.launch_tor_with_config(
|
||||
|
@ -49,6 +50,7 @@ class TorInstance():
|
|||
self.data_dir = ""
|
||||
self.history = None
|
||||
self.proxy = ""
|
||||
self.headers = {}
|
||||
self.session = None
|
||||
self.process = None
|
||||
|
||||
|
@ -72,6 +74,7 @@ class TorInstance():
|
|||
conn = ProxyConnector(remote_resolve=True)
|
||||
self.session = aiohttp.ClientSession(
|
||||
connector=conn,
|
||||
headers=self.headers,
|
||||
request_class=ProxyClientRequest
|
||||
)
|
||||
|
||||
|
@ -105,7 +108,7 @@ class TorInstance():
|
|||
async def main():
|
||||
""" Test function """
|
||||
for _ in range(3):
|
||||
instance = await TorInstance.create(None)
|
||||
instance = await TorInstance.create(None, {"user-agent" : "Blah"})
|
||||
await instance.query("https://python.org/")
|
||||
print("One page received")
|
||||
await instance.kill()
|
||||
|
|
Loading…
Reference in a new issue