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

Snake case + bug fixes #835

Merged
merged 9 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ __pycache__/
db/test.txt

default.conf

.ropeproject/
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- [Kyle Nweeia](https://github.com/kyle-nweeia)
- [Xib3rR4dAr](https://github.com/Xib3rR4dAr)
- [Rohit Soni](https://github.com/StreetOfHackerR007/)
- [Maxime Peim](https://github.com/maxime-peim)

Special thanks for all the people who had helped dirsearch so far!

Expand Down
56 changes: 28 additions & 28 deletions lib/connection/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class Requester(object):
def __init__(
self,
url,
maxPool=1,
maxRetries=5,
max_pool=1,
max_retries=5,
timeout=20,
ip=None,
proxy=None,
proxylist=None,
redirect=False,
requestByHostname=False,
request_by_hostname=False,
httpmethod="get",
data=None,
scheme=None,
Expand All @@ -67,19 +67,19 @@ def __init__(
raise RequestException({"message": "Unsupported URL scheme: {0}".format(parsed.scheme)})

if parsed.path.startswith("/"):
self.basePath = parsed.path[1:]
self.base_path = parsed.path[1:]
else:
self.basePath = parsed.path
self.base_path = parsed.path

# Safe quote all special characters in basePath to prevent from being encoded when performing requests
self.basePath = urllib.parse.quote(self.basePath, safe="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
# Safe quote all special characters in base_path to prevent from being encoded when performing requests
self.base_path = urllib.parse.quote(self.base_path, safe="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
self.protocol = parsed.scheme
self.host = parsed.netloc.split(":")[0]

# Resolve DNS to decrease overhead
if ip:
self.ip = ip
# A proxy could have a different DNS that would resolve the name. Therefore,
# A proxy could have a different DNS that would resolve the name. ThereFore.
# resolving the name when using proxy to raise an error is pointless
elif not proxy and not proxylist:
try:
Expand All @@ -106,37 +106,37 @@ def __init__(
):
self.headers["Host"] += ":{0}".format(self.port)

self.maxRetries = maxRetries
self.maxPool = maxPool
self.max_retries = max_retries
self.max_pool = max_pool
self.timeout = timeout
self.pool = None
self.proxy = proxy
self.proxylist = proxylist
self.redirect = redirect
self.randomAgents = None
self.random_agents = None
self.auth = None
self.requestByHostname = requestByHostname
self.request_by_hostname = request_by_hostname
self.session = requests.Session()
self.url = "{0}://{1}:{2}/".format(
self.protocol,
self.host if self.requestByHostname else self.ip,
self.host if self.request_by_hostname else self.ip,
self.port,
)
self.baseUrl = "{0}://{1}:{2}/".format(
self.base_url = "{0}://{1}:{2}/".format(
self.protocol,
self.host,
self.port,
)

def setHeader(self, key, value):
def set_header(self, key, value):
self.headers[key.strip()] = value.strip() if value else value

def setRandomAgents(self, agents):
self.randomAgents = list(agents)
def set_random_agents(self, agents):
self.random_agents = list(agents)

def setAuth(self, type, credential):
def set_auth(self, type, credential):
if type == "bearer":
self.setHeader("Authorization", "Bearer {0}".format(credential))
self.set_header("Authorization", "Bearer {0}".format(credential))
else:
user = credential.split(":")[0]
try:
Expand All @@ -155,7 +155,7 @@ def request(self, path, proxy=None):
result = None
error = None

for i in range(self.maxRetries):
for i in range(self.max_retries):
try:
if not proxy:
if self.proxylist:
Expand All @@ -176,10 +176,10 @@ def request(self, path, proxy=None):
else:
proxies = None

url = self.url + self.basePath + path
url = self.url + self.base_path + path

if self.randomAgents:
self.headers["User-Agent"] = random.choice(self.randomAgents)
if self.random_agents:
self.headers["User-Agent"] = random.choice(self.random_agents)

request = requests.Request(
self.httpmethod,
Expand Down Expand Up @@ -207,11 +207,11 @@ def request(self, path, proxy=None):
break

except requests.exceptions.SSLError:
self.url = self.baseUrl
self.url = self.base_url
continue

except requests.exceptions.TooManyRedirects:
error = "Too many redirects: {0}".format(self.baseUrl)
error = "Too many redirects: {0}".format(self.base_url)

except requests.exceptions.ProxyError:
error = "Error with the proxy: {0}".format(proxy)
Expand All @@ -220,7 +220,7 @@ def request(self, path, proxy=None):
error = "Cannot connect to: {0}:{1}".format(self.host, self.port)

except requests.exceptions.InvalidURL:
error = "Invalid URL: {0}".format(self.baseUrl)
error = "Invalid URL: {0}".format(self.base_url)

except requests.exceptions.InvalidProxyURL:
error = "Invalid proxy URL: {0}".format(proxy)
Expand All @@ -232,10 +232,10 @@ def request(self, path, proxy=None):
http.client.IncompleteRead,
socket.timeout,
):
error = "Request timeout: {0}".format(self.baseUrl)
error = "Request timeout: {0}".format(self.base_url)

except Exception:
error = "There was a problem in the request to: {0}".format(self.baseUrl)
error = "There was a problem in the request to: {0}".format(self.base_url)

if error:
raise RequestException({"message": error})
Expand Down
Loading