aboutsummaryrefslogtreecommitdiffstats
path: root/pathod/pathoc.py
diff options
context:
space:
mode:
Diffstat (limited to 'pathod/pathoc.py')
-rw-r--r--pathod/pathoc.py77
1 files changed, 42 insertions, 35 deletions
diff --git a/pathod/pathoc.py b/pathod/pathoc.py
index 5cfb4591..3eb91637 100644
--- a/pathod/pathoc.py
+++ b/pathod/pathoc.py
@@ -247,7 +247,10 @@ class Pathoc(tcp.TCPClient):
def socks_connect(self, connect_to):
try:
- client_greet = socks.ClientGreeting(socks.VERSION.SOCKS5, [socks.METHOD.NO_AUTHENTICATION_REQUIRED])
+ client_greet = socks.ClientGreeting(
+ socks.VERSION.SOCKS5,
+ [socks.METHOD.NO_AUTHENTICATION_REQUIRED]
+ )
client_greet.to_file(self.wfile)
self.wfile.flush()
@@ -286,44 +289,47 @@ class Pathoc(tcp.TCPClient):
if self.use_http2 and not self.ssl:
raise NotImplementedError("HTTP2 without SSL is not supported.")
- ret = tcp.TCPClient.connect(self)
+ try:
+ ret = tcp.TCPClient.connect(self)
+ if connect_to:
+ self.http_connect(connect_to)
- if connect_to:
- self.http_connect(connect_to)
+ self.sslinfo = None
+ if self.ssl:
+ try:
+ alpn_protos = [b'http/1.1']
+ if self.use_http2:
+ alpn_protos.append(b'h2')
+
+ self.convert_to_ssl(
+ sni=self.sni,
+ cert=self.clientcert,
+ method=self.ssl_version,
+ options=self.ssl_options,
+ cipher_list=self.ciphers,
+ alpn_protos=alpn_protos
+ )
+ except TlsException as v:
+ raise PathocError(str(v))
- self.sslinfo = None
- if self.ssl:
- try:
- alpn_protos = [b'http/1.1']
- if self.use_http2:
- alpn_protos.append(b'h2')
-
- self.convert_to_ssl(
- sni=self.sni,
- cert=self.clientcert,
- method=self.ssl_version,
- options=self.ssl_options,
- cipher_list=self.ciphers,
- alpn_protos=alpn_protos
+ self.sslinfo = SSLInfo(
+ self.connection.get_peer_cert_chain(),
+ self.get_current_cipher(),
+ self.get_alpn_proto_negotiated()
)
- except TlsException as v:
- raise PathocError(str(v))
-
- self.sslinfo = SSLInfo(
- self.connection.get_peer_cert_chain(),
- self.get_current_cipher(),
- self.get_alpn_proto_negotiated()
- )
- if showssl:
- print(str(self.sslinfo), file=fp)
-
- if self.use_http2:
- self.protocol.check_alpn()
- if not self.http2_skip_connection_preface:
- self.protocol.perform_client_connection_preface()
+ if showssl:
+ print(str(self.sslinfo), file=fp)
- if self.timeout:
- self.settimeout(self.timeout)
+ if self.use_http2:
+ self.protocol.check_alpn()
+ if not self.http2_skip_connection_preface:
+ self.protocol.perform_client_connection_preface()
+
+ if self.timeout:
+ self.settimeout(self.timeout)
+ except Exception:
+ self.close()
+ raise
return ret
def stop(self):
@@ -355,6 +361,7 @@ class Pathoc(tcp.TCPClient):
return
if frm is None:
self.ws_framereader.join()
+ self.ws_framereader = None
return
yield frm