Update store.py
Browse files
store.py
CHANGED
|
@@ -43,9 +43,24 @@ def _hdr(extra=None):
|
|
| 43 |
return h
|
| 44 |
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def _get_json(url, timeout=30):
|
| 47 |
req = urllib.request.Request(url, headers=_hdr())
|
| 48 |
-
with
|
| 49 |
return json.loads(r.read().decode())
|
| 50 |
|
| 51 |
|
|
|
|
| 43 |
return h
|
| 44 |
|
| 45 |
|
| 46 |
+
class _DropAuthOnRedirect(urllib.request.HTTPRedirectHandler):
|
| 47 |
+
"""Large files are served from a CDN via a signed redirect; the Hub token must not
|
| 48 |
+
follow the request to another host (the CDN rejects it with 400)."""
|
| 49 |
+
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
| 50 |
+
new = super().redirect_request(req, fp, code, msg, headers, newurl)
|
| 51 |
+
if new is not None:
|
| 52 |
+
from urllib.parse import urlsplit
|
| 53 |
+
if urlsplit(newurl).netloc != urlsplit(req.full_url).netloc:
|
| 54 |
+
new.remove_header("Authorization")
|
| 55 |
+
return new
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
_OPENER = urllib.request.build_opener(_DropAuthOnRedirect)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
def _get_json(url, timeout=30):
|
| 62 |
req = urllib.request.Request(url, headers=_hdr())
|
| 63 |
+
with _OPENER.open(req, timeout=timeout) as r:
|
| 64 |
return json.loads(r.read().decode())
|
| 65 |
|
| 66 |
|