From ddf2937f5be1bc9e7b6d5cf7a2fc63d81ff394e3 Mon Sep 17 00:00:00 2001 From: fabpiaf <144336756+fabpiaf@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:39:04 +0000 Subject: [PATCH 1/2] Update messaging.py for proxy use proxy wrapping via monkey patching --- restler/engine/transport_layer/messaging.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/restler/engine/transport_layer/messaging.py b/restler/engine/transport_layer/messaging.py index c9ce4d9c..0ab38618 100644 --- a/restler/engine/transport_layer/messaging.py +++ b/restler/engine/transport_layer/messaging.py @@ -7,6 +7,8 @@ import socket import time import threading +import os +import socks from importlib import util from utils.logging.trace_db import (DB as TraceDatabase, SequenceTracker) @@ -74,6 +76,21 @@ def __init__(self, connection_settings): self._connected = False self._sock = None + proxy=os.environ.get('RESTLER_PROXY') + if proxy: + import re + pptype,username,password,addr,port=re.search('(?:([^:]+)://)?(?:([^:]+)(?::([^:]+)?)?@)?([^:]+)(?::(\d{1,5}))?', proxy, re.IGNORECASE).groups() + ptypes={ + "http":socks.HTTP, + "socks4":socks.SOCKS4, + "socks5":socks.SOCKS5, + } + ptype=ptypes.get(pptype,socks.HTTP) + port=int(port) + print(f'proxy {ptype} {addr} {port}') + socks.set_default_proxy(proxy_type=ptype, addr=addr, port=port, rdns=True, username=username, password=password) + socket.socket = socks.socksocket + def __del__(self): """ Destructor - Closes socket From dc98ae655be4642f62715f91a656dd4577d282e8 Mon Sep 17 00:00:00 2001 From: fabpiaf <144336756+fabpiaf@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:54:45 +0000 Subject: [PATCH 2/2] Update requirements.txt add pysocks for proxy support --- restler/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/restler/requirements.txt b/restler/requirements.txt index b60b27a2..81ade9ba 100644 --- a/restler/requirements.txt +++ b/restler/requirements.txt @@ -1,2 +1,3 @@ applicationinsights -pytest \ No newline at end of file +pytest +pysocks