Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update messaging.py for proxy use #875

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions restler/engine/transport_layer/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion restler/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
applicationinsights
pytest
pytest
pysocks