Files
Arjun/arjun/core/error_handler.py

59 lines
1.7 KiB
Python
Raw Normal View History

import time
2021-02-07 19:43:30 +05:30
import arjun.core.config as mem
2021-02-07 19:43:30 +05:30
from arjun.core.colors import bad
def connection_refused():
2021-02-07 19:43:30 +05:30
"""
checks if a request should be retried if the server refused connection
returns str
"""
if mem.var['stable']:
2021-02-07 19:43:30 +05:30
print('%s Hit rate limit, stabilizing the connection' % bad)
mem.var['kill'] = False
time.sleep(30)
return 'retry'
print('%s Target has rate limiting in place, please use --stable switch' % bad)
return 'kill'
def error_handler(response, factors):
2021-02-07 19:43:30 +05:30
"""
decides what to do after performing a HTTP request
'ok': continue normally
'retry': retry this request
'kill': stop processing this target
returns str
"""
if type(response) != str and response.status_code in (400, 503, 429):
if response.status_code == 400:
if factors['same_code'] != 400:
mem.var['kill'] = True
2022-03-01 03:20:50 +01:00
print('%s Server received a bad request. Try decreasing the chunk size with -c option' % bad)
return 'kill'
else:
return 'ok'
elif response.status_code == 503:
mem.var['kill'] = True
print('%s Target is unable to process requests, try --stable switch' % bad)
return 'kill'
elif response.status_code == 429:
return connection_refused()
else:
if 'Timeout' in response:
if mem.var['timeout'] > 20:
mem.var['kill'] = True
2021-05-10 11:35:08 +05:30
print('%s Connection timed out, unable to increase timeout further' % bad)
return 'kill'
else:
2021-02-07 19:43:30 +05:30
print('%s Connection timed out, increased timeout by 5 seconds' % bad)
mem.var['timeout'] += 5
return 'retry'
elif 'ConnectionRefused' in response:
return connection_refused()
elif type(response) == str:
2021-03-11 05:56:17 +05:30
if '\'' in response:
print('%s Encountered an error: %s' % (bad, response.split('\'')[1]))
return 'kill'
return 'ok'