From 71d9e18eec4eae79c6b5d854eabca20f86bf61b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Sun, 25 Feb 2018 23:56:51 +0100 Subject: [PATCH] Add headers support --- histories/tor_runner.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/histories/tor_runner.py b/histories/tor_runner.py index 97bbc33..08e6620 100644 --- a/histories/tor_runner.py +++ b/histories/tor_runner.py @@ -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()