mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-02-11 20:47:55 +01:00
Fix debug traffic for websockets proxy
This commit is contained in:
parent
6dcc99ee4a
commit
976cec10c9
2 changed files with 23 additions and 1 deletions
|
@ -307,6 +307,7 @@ def create_http_connect_connection(
|
|||
source_address=None,
|
||||
username=None,
|
||||
password=None,
|
||||
debug=False,
|
||||
):
|
||||
|
||||
proxy_headers = dict()
|
||||
|
@ -316,6 +317,8 @@ def create_http_connect_connection(
|
|||
f'{username or ""}:{password or ""}'.encode('utf-8')).decode('utf-8')
|
||||
|
||||
conn = HTTPConnection(proxy_host, port=proxy_port, timeout=timeout)
|
||||
conn.set_debuglevel(int(debug))
|
||||
|
||||
conn.response_class = NoCloseHTTPResponse
|
||||
|
||||
if hasattr(conn, '_create_connection'):
|
||||
|
|
|
@ -4,7 +4,6 @@ import contextlib
|
|||
import io
|
||||
import logging
|
||||
import ssl
|
||||
import sys
|
||||
import urllib.parse
|
||||
|
||||
from ._helper import (
|
||||
|
@ -70,6 +69,25 @@ with contextlib.suppress(Exception):
|
|||
websockets.sync.connection.Connection.recv_events_exc = None
|
||||
|
||||
|
||||
class WebsocketsLoggingHandler(logging.Handler):
|
||||
"""Redirect websocket logs to our logger"""
|
||||
|
||||
def __init__(self, logger, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._logger = logger
|
||||
|
||||
def emit(self, record):
|
||||
try:
|
||||
msg = self.format(record)
|
||||
if record.levelno >= logging.ERROR:
|
||||
self._logger.error(msg)
|
||||
else:
|
||||
self._logger.stdout(msg)
|
||||
|
||||
except Exception:
|
||||
self.handleError(record)
|
||||
|
||||
|
||||
class WebsocketsResponseAdapter(WebSocketResponse):
|
||||
|
||||
def __init__(self, ws: websockets.sync.client.ClientConnection, url):
|
||||
|
@ -181,6 +199,7 @@ class WebsocketsRH(WebSocketRequestHandler):
|
|||
source_address=self.source_address,
|
||||
username=parsed_proxy_url.username,
|
||||
password=parsed_proxy_url.password,
|
||||
debug=self.verbose,
|
||||
)
|
||||
return create_connection(
|
||||
address=(parsed_url.host, parsed_url.port),
|
||||
|
|
Loading…
Add table
Reference in a new issue