mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-05-13 16:35:43 -05:00
Fix unclosed socket errors
This commit is contained in:
parent
a14bb53ab5
commit
bff727c043
1 changed files with 13 additions and 2 deletions
|
@ -59,7 +59,9 @@ def __init__(self, *args, proxy_info=None, username=None, password=None, request
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
self.do_proxy_auth(self.username, self.password)
|
if not self.do_proxy_auth(self.username, self.password):
|
||||||
|
self.server.close_request(self.request)
|
||||||
|
return
|
||||||
if self.path.endswith('/proxy_info'):
|
if self.path.endswith('/proxy_info'):
|
||||||
payload = json.dumps(self.proxy_info or {
|
payload = json.dumps(self.proxy_info or {
|
||||||
'client_address': self.client_address,
|
'client_address': self.client_address,
|
||||||
|
@ -75,6 +77,11 @@ def do_GET(self):
|
||||||
self.send_header('Content-Length', str(len(payload)))
|
self.send_header('Content-Length', str(len(payload)))
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(payload.encode())
|
self.wfile.write(payload.encode())
|
||||||
|
else:
|
||||||
|
self.send_response(404)
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
self.server.close_request(self.request)
|
||||||
|
|
||||||
|
|
||||||
if urllib3:
|
if urllib3:
|
||||||
|
@ -135,7 +142,9 @@ def __init__(self, *args, username=None, password=None, request_handler=None, **
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def do_CONNECT(self):
|
def do_CONNECT(self):
|
||||||
self.do_proxy_auth(self.username, self.password)
|
if not self.do_proxy_auth(self.username, self.password):
|
||||||
|
self.server.close_request(self.request)
|
||||||
|
return
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
proxy_info = {
|
proxy_info = {
|
||||||
|
@ -148,6 +157,7 @@ def do_CONNECT(self):
|
||||||
'proxy': ':'.join(str(y) for y in self.connection.getsockname()),
|
'proxy': ':'.join(str(y) for y in self.connection.getsockname()),
|
||||||
}
|
}
|
||||||
self.request_handler(self.request, self.client_address, self.server, proxy_info=proxy_info)
|
self.request_handler(self.request, self.client_address, self.server, proxy_info=proxy_info)
|
||||||
|
self.server.close_request(self.request)
|
||||||
|
|
||||||
|
|
||||||
class HTTPSConnectProxyHandler(HTTPConnectProxyHandler):
|
class HTTPSConnectProxyHandler(HTTPConnectProxyHandler):
|
||||||
|
@ -249,6 +259,7 @@ def test_http_bad_auth(self, handler, ctx):
|
||||||
with pytest.raises(HTTPError) as exc_info:
|
with pytest.raises(HTTPError) as exc_info:
|
||||||
ctx.proxy_info_request(rh)
|
ctx.proxy_info_request(rh)
|
||||||
assert exc_info.value.response.status == 407
|
assert exc_info.value.response.status == 407
|
||||||
|
exc_info.value.response.close()
|
||||||
|
|
||||||
def test_http_source_address(self, handler, ctx):
|
def test_http_source_address(self, handler, ctx):
|
||||||
with ctx.http_server(HTTPProxyHandler) as server_address:
|
with ctx.http_server(HTTPProxyHandler) as server_address:
|
||||||
|
|
Loading…
Reference in a new issue