Skip to content

Commit 09d4752

Browse files
committed
Merge branch 'master' of https://github.com/qwj/python-proxy
python 3.11 compatibility
2 parents 2e18d25 + e03384f commit 09d4752

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

‎pproxy/proto.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ async def connected(writer):
328328
writer.write(f'{method}{newpath}{ver}\r\n{lines}\r\n\r\n'.encode())
329329
returnTrue
330330
returnuser, host_name, port, connected
331-
asyncdefconnect(self, reader_remote, writer_remote, rauth, host_name, port, myhost, **kw):
332-
writer_remote.write(f'CONNECT {host_name}:{port} HTTP/1.1\r\nHost: {myhost}'.encode() + (b'\r\nProxy-Authorization: Basic '+base64.b64encode(rauth) ifrauthelseb'') +b'\r\n\r\n')
331+
asyncdefconnect(self, reader_remote, writer_remote, rauth, host_name, port, **kw):
332+
writer_remote.write(f'CONNECT {host_name}:{port} HTTP/1.1\r\nHost: {host_name}:{port}'.encode() + (b'\r\nProxy-Authorization: Basic '+base64.b64encode(rauth) ifrauthelseb'') +b'\r\n\r\n')
333333
awaitreader_remote.read_until(b'\r\n\r\n')
334334
asyncdefhttp_channel(self, reader, writer, stat_bytes, stat_conn):
335335
try:
@@ -616,12 +616,21 @@ def abort(self):
616616
self.close()
617617
ssl.connection_made(Transport())
618618
asyncdefchannel():
619+
read_size=65536
620+
buffer=None
621+
ifhasattr(ssl,'get_buffer'):
622+
buffer=ssl.get_buffer(read_size)
619623
try:
620624
whilenotreader.at_eof() andnotssl._app_transport._closed:
621-
data=awaitreader.read(65536)
625+
data=awaitreader.read(read_size)
622626
ifnotdata:
623627
break
624-
ssl.data_received(data)
628+
ifbuffer!=None:
629+
data_len=len(data)
630+
buffer[:data_len]=data
631+
ssl.buffer_updated(data_len)
632+
else:
633+
ssl.data_received(data)
625634
exceptException:
626635
pass
627636
finally:

‎pproxy/server.py‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,17 @@ async def test_url(url, rserver):
880880
print(body.decode('utf8', 'ignore'))
881881
print(f'============ success ============')
882882

883+
defprint_server_started(option, server, print_fn):
884+
forsinserver.sockets:
885+
# https://github.com/MagicStack/uvloop/blob/master/uvloop/pseudosock.pyx
886+
laddr=s.getsockname() # tuple size varies with protocol family
887+
h=laddr[0]
888+
p=laddr[1]
889+
f=str(s.family)
890+
ipversion="ipv4"iff=="AddressFamily.AF_INET"else ("ipv6"iff=="AddressFamily.AF_INET6"else"ipv?") # TODO better
891+
bind=ipversion+' '+h+':'+str(p)
892+
print_fn(option, bind)
893+
883894
defmain(args=None):
884895
parser=argparse.ArgumentParser(description=__description__+'\nSupported protocols: http,socks4,socks5,shadowsocks,shadowsocksr,redirect,pf,tunnel', epilog=f'Online help: <{__url__}>')
885896
parser.add_argument('-l', dest='listen', default=[], action='append', type=proxies_by_uri, help='tcp server uri (default: http+socks4+socks5://:8080/)')
@@ -942,27 +953,36 @@ def main(args = None):
942953
from . importverbose
943954
verbose.setup(loop, args)
944955
servers= []
956+
defprint_fn(option, bind=None):
957+
print('Serving on', (bindoroption.bind), 'by', ",".join(i.nameforiinoption.protos) + ('(SSL)'ifoption.sslclientelse''), '({}{})'.format(option.cipher.name, ' '+','.join(i.name() foriinoption.cipher.plugins) ifoption.cipherandoption.cipher.pluginselse'') ifoption.cipherelse'')
945958
foroptioninargs.listen:
946-
print('Serving on', option.bind, 'by', ",".join(i.nameforiinoption.protos) + ('(SSL)'ifoption.sslclientelse''), '({}{})'.format(option.cipher.name, ' '+','.join(i.name() foriinoption.cipher.plugins) ifoption.cipherandoption.cipher.pluginselse'') ifoption.cipherelse'')
947959
try:
948960
server=loop.run_until_complete(option.start_server(vars(args)))
961+
print_server_started(option, server, print_fn)
949962
servers.append(server)
950963
exceptExceptionasex:
964+
print_fn(option)
951965
print('Start server failed.\n\t==>', ex)
966+
defprint_fn(option, bind=None):
967+
print('Serving on UDP', (bindoroption.bind), 'by', ",".join(i.nameforiinoption.protos), f'({option.cipher.name})'ifoption.cipherelse'')
952968
foroptioninargs.ulisten:
953-
print('Serving on UDP', option.bind, 'by', ",".join(i.nameforiinoption.protos), f'({option.cipher.name})'ifoption.cipherelse'')
954969
try:
955970
server, protocol=loop.run_until_complete(option.udp_start_server(vars(args)))
971+
print_server_started(option, server, print_fn)
956972
servers.append(server)
957973
exceptExceptionasex:
974+
print_fn(option)
958975
print('Start server failed.\n\t==>', ex)
976+
defprint_fn(option, bind=None):
977+
print('Serving on', (bindoroption.bind), 'backward by', ",".join(i.nameforiinoption.protos) + ('(SSL)'ifoption.sslclientelse''), '({}{})'.format(option.cipher.name, ' '+','.join(i.name() foriinoption.cipher.plugins) ifoption.cipherandoption.cipher.pluginselse'') ifoption.cipherelse'')
959978
foroptioninargs.rserver:
960979
ifisinstance(option, ProxyBackward):
961-
print('Serving on', option.bind, 'backward by', ",".join(i.nameforiinoption.protos) + ('(SSL)'ifoption.sslclientelse''), '({}{})'.format(option.cipher.name, ' '+','.join(i.name() foriinoption.cipher.plugins) ifoption.cipherandoption.cipher.pluginselse'') ifoption.cipherelse'')
962980
try:
963981
server=loop.run_until_complete(option.start_backward_client(vars(args)))
982+
print_server_started(option, server, print_fn)
964983
servers.append(server)
965984
exceptExceptionasex:
985+
print_fn(option)
966986
print('Start server failed.\n\t==>', ex)
967987
ifservers:
968988
ifargs.sys:

0 commit comments

Comments
(0)