rocksock/http2: bump to latest

This commit is contained in:
rofl0r
2019-01-08 15:42:03 +00:00
parent b88a8426dc
commit b6839eea79
2 changed files with 24 additions and 6 deletions

View File

@@ -75,7 +75,10 @@ def _is_textual_content_type(ct):
return ct in TEXTUAL_CONTENT_TYPES_LIST
class RsHttp():
def __init__(self, host, port=80, ssl=False, follow_redirects=False, auto_set_cookies=False, keep_alive=False, timeout=60, user_agent=None, proxies=None, max_tries=10, log_errors=True, **kwargs):
def __init__(self, host, port=80, ssl=False, follow_redirects=False, \
auto_set_cookies=False, keep_alive=False, timeout=60, \
user_agent=None, proxies=None, max_tries=10, log_errors=True, \
**kwargs):
self.host = host
self.port = port
self.use_ssl = ssl
@@ -89,8 +92,12 @@ class RsHttp():
self.cookies = dict()
self.max_tries = max_tries
self.log_errors = log_errors
self.last_rs_exception = None
self.headers = []
def get_last_rocksock_exception(self):
return self.last_rs_exception
def _err_log(self, s):
if self.log_errors:
sys.stderr.write(s + '\n')
@@ -244,6 +251,7 @@ class RsHttp():
self.conn.connect()
return True
except RocksockException as e:
self.last_rs_exception = e
if e.errortype == rocksock.RS_ET_GAI and e.error==-2:
# -2: Name does not resolve
self.conn.disconnect()
@@ -279,6 +287,7 @@ class RsHttp():
try:
return func(*args)
except RocksockException as e:
self.last_rs_exception = e
self.conn.disconnect()
if not self.reconnect(): return failret
except IOError:

View File

@@ -1,4 +1,4 @@
import socket, ssl, select, copy
import socket, ssl, select, copy, errno
# rs_proxyType
RS_PT_NONE = 0
@@ -31,9 +31,13 @@ RS_E_HIT_READTIMEOUT = 14
RS_E_HIT_WRITETIMEOUT = 15
RS_E_HIT_CONNECTTIMEOUT = 16
RS_E_PROXY_GENERAL_FAILURE = 17
RS_E_TARGET_NET_UNREACHABLE = 18
RS_E_TARGETPROXY_NET_UNREACHABLE = 18
RS_E_TARGET_HOST_UNREACHABLE = 19
RS_E_TARGETPROXY_HOST_UNREACHABLE = 19
RS_E_TARGET_CONN_REFUSED = 20
RS_E_TARGETPROXY_CONN_REFUSED = 20
RS_E_TARGET_TTL_EXPIRED = 21
RS_E_TARGETPROXY_TTL_EXPIRED = 21
RS_E_PROXY_COMMAND_NOT_SUPPORTED = 22
RS_E_PROXY_ADDRESSTYPE_NOT_SUPPORTED = 23
@@ -99,7 +103,6 @@ class RocksockException(Exception):
RS_E_INVALID_PROXY_URL : "invalid proxy URL string"
}
if self.errortype == RS_ET_SYS:
import errno
if self.error in errno.errorcode:
msg = "ERRNO: " + errno.errorcode[self.error]
else:
@@ -168,6 +171,12 @@ class Rocksock():
self.sock = None
self.timeout = timeout
def _translate_socket_error(self, e, pnum):
fp = self._failed_proxy(pnum)
if e.errno == errno.ECONNREFUSED:
return RocksockException(RS_E_TARGET_CONN_REFUSED, failedproxy=fp)
return RocksockException(e.errno, errortype=RS_ET_SYS, failedproxy=fp)
def _failed_proxy(self, pnum):
if pnum < 0: return -1
if pnum >= len(self.proxychain)-1: return -1
@@ -191,7 +200,7 @@ class Rocksock():
except socket.timeout:
raise RocksockException(RS_E_HIT_TIMEOUT, failedproxy=self._failed_proxy(0))
except socket.error as e:
raise RocksockException(e.errno, errortype=RS_ET_SYS, failedproxy=self._failed_proxy(0))
raise self._translate_socket_error(e, 0)
for pnum in xrange(1, len(self.proxychain)):
curr = self.proxychain[pnum]
@@ -206,7 +215,7 @@ class Rocksock():
#if hasattr(e, 'library'): subsystem = e.library
raise RocksockException(RS_E_SSL_GENERIC, failedproxy=reason, errortype=RS_ET_SSL)
except socket.error as e:
raise RocksockException(e.errno, errortype=RS_ET_SYS)
raise self._translate_socket_error(e, -1)
except Exception as e:
raise e
"""
@@ -255,7 +264,7 @@ class Rocksock():
except socket.timeout:
raise RocksockException(RS_E_HIT_TIMEOUT, failedproxy=self._failed_proxy(pnum))
except socket.error as e:
raise RocksockException(e.errno, errortype=RS_ET_SYS, failedproxy=self._failed_proxy(pnum))
raise self._translate_socket_error(e, pnum)
except ssl.SSLError as e:
s = self._get_ssl_exception_reason(e)
if s == 'The read operation timed out':