vivekchakraverty commited on
Commit
2f66665
·
verified ·
1 Parent(s): 2c99193

Trust YT_PROXY_CA for HTTPS proxy; expand reachability probe battery

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py CHANGED
@@ -19,6 +19,31 @@ import shutil
19
  import tempfile
20
  import time
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  import gradio as gr
23
 
24
  from pipeline import (
@@ -122,6 +147,8 @@ def check_access():
122
  probes = [
123
  ("example.com (neutral)", "https://example.com"),
124
  ("google.com/204 (Google cert, non-YT name)", "https://www.google.com/generate_204"),
 
 
125
  ("youtube.com/robots.txt", "https://www.youtube.com/robots.txt"),
126
  ("youtube.com/ (large body)", "https://www.youtube.com/"),
127
  ]
 
19
  import tempfile
20
  import time
21
 
22
+
23
+ def _install_proxy_ca() -> None:
24
+ """Trust a self-signed proxy CA (secret ``YT_PROXY_CA``) alongside the system
25
+ roots, so an HTTPS (TLS-wrapped) ``YT_PROXY`` validates. TLS-wrapping hides the
26
+ target host (``CONNECT www.youtube.com``) from the Space's egress DPI, which
27
+ otherwise resets YouTube-bound connections. Covers requests / youtube-transcript-api
28
+ (``REQUESTS_CA_BUNDLE``) and stdlib ssl / yt-dlp (``SSL_CERT_FILE``)."""
29
+ ca = os.environ.get("YT_PROXY_CA", "").strip()
30
+ if not ca:
31
+ return
32
+ try:
33
+ import certifi
34
+ bundle = os.path.join(tempfile.gettempdir(), "yt_proxy_ca_bundle.pem")
35
+ with open(certifi.where(), encoding="utf-8") as fh:
36
+ roots = fh.read()
37
+ with open(bundle, "w", encoding="utf-8") as fh:
38
+ fh.write(roots.rstrip() + "\n" + ca + "\n")
39
+ os.environ["REQUESTS_CA_BUNDLE"] = bundle
40
+ os.environ["SSL_CERT_FILE"] = bundle
41
+ except Exception:
42
+ pass
43
+
44
+
45
+ _install_proxy_ca()
46
+
47
  import gradio as gr
48
 
49
  from pipeline import (
 
147
  probes = [
148
  ("example.com (neutral)", "https://example.com"),
149
  ("google.com/204 (Google cert, non-YT name)", "https://www.google.com/generate_204"),
150
+ ("i.ytimg.com (YT image CDN)", "https://i.ytimg.com/generate_204"),
151
+ ("youtubei.googleapis.com (YT API)", "https://youtubei.googleapis.com/generate_204"),
152
  ("youtube.com/robots.txt", "https://www.youtube.com/robots.txt"),
153
  ("youtube.com/ (large body)", "https://www.youtube.com/"),
154
  ]