Skip to content

Commit 44a16e7

Browse files
authored
Use CORS proxy in aiohttp
1 parent ddb3cc3 commit 44a16e7

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

patches/pyodide.patch

+46-10
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ index 9a3c91ae..0632c904 100644
218218
run:
219219
diff --git a/packages/aiohttp/patches/0001-pyodide-connection.patch b/packages/aiohttp/patches/0001-pyodide-connection.patch
220220
new file mode 100644
221-
index 00000000..c9603ab2
221+
index 00000000..c467f617
222222
--- /dev/null
223223
+++ b/packages/aiohttp/patches/0001-pyodide-connection.patch
224-
@@ -0,0 +1,293 @@
224+
@@ -0,0 +1,306 @@
225225
+diff --git a/aiohttp/__init__.py b/aiohttp/__init__.py
226226
+index 8bc7a4aa..b6debab6 100644
227227
+--- a/aiohttp/__init__.py
@@ -234,10 +234,10 @@ index 00000000..c9603ab2
234234
++from . import patch
235235
+diff --git a/aiohttp/patch.py b/aiohttp/patch.py
236236
+new file mode 100644
237-
+index 00000000..fc6e65d1
237+
+index 00000000..1797e846
238238
+--- /dev/null
239239
++++ b/aiohttp/patch.py
240-
+@@ -0,0 +1,277 @@
240+
+@@ -0,0 +1,290 @@
241241
++from collections.abc import Iterable
242242
++from contextlib import suppress
243243
++from io import BytesIO
@@ -428,14 +428,21 @@ index 00000000..c9603ab2
428428
++ session=req._session,
429429
++ )
430430
++
431-
++ from js import XMLHttpRequest
431+
++ import js
432432
++ from pyodide.ffi import to_js
433433
++
434-
++ xhr = XMLHttpRequest.new()
434+
++ xhr = js.XMLHttpRequest.new()
435435
++ xhr.responseType = "arraybuffer"
436436
++ xhr.timeout = int(real_timeout.total * 1000)
437437
++
438-
++ xhr.open(req.method, str(req.url), False)
438+
++ url = str(req.url)
439+
++ same_origin = js.URL.new(url).origin == js.location.origin
440+
++
441+
++ # use a CORS proxy for cross-origin requests
442+
++ if not same_origin:
443+
++ url = f"https://proxy.climet.eu/{url}"
444+
++
445+
++ xhr.open(req.method, url, False)
439446
++ for name, value in headers.items():
440447
++ if name.lower() not in ("user-agent",):
441448
++ xhr.setRequestHeader(name, value)
@@ -445,9 +452,15 @@ index 00000000..c9603ab2
445452
++ from email.parser import Parser
446453
++ headers = dict(Parser().parsestr(xhr.getAllResponseHeaders()))
447454
++ body = xhr.response.to_py().tobytes()
455+
++ status = xhr.status
456+
++
457+
++ # redirect codes 301, 302, 303, 307, and 308 are hidden in 2xx codes
458+
++ # by the proxy since browsers follow redirects automatically
459+
++ if (not same_origin) and (status in [251, 252, 253, 257, 258]):
460+
++ status += 50
448461
++
449462
++ resp.version = version
450-
++ resp.status = xhr.status
463+
++ resp.status = status
451464
++ resp.reason = xhr.statusText
452465
++ # This is not quite correct in handling of repeated headers
453466
++ resp._headers = CIMultiDict(headers)
@@ -2072,8 +2085,31 @@ index 00000000..98de1e7b
20722085
+ vendor-sharedlib: true
20732086
+ script: |
20742087
+ cp ${WASM_LIBRARY_DIR}/lib/libgit2.so git2/
2088+
diff --git a/packages/h5netcdf/meta.yaml b/packages/h5netcdf/meta.yaml
2089+
new file mode 100644
2090+
index 00000000..59d3abbf
2091+
--- /dev/null
2092+
+++ b/packages/h5netcdf/meta.yaml
2093+
@@ -0,0 +1,17 @@
2094+
+package:
2095+
+ name: h5netcdf
2096+
+ version: 1.3.0
2097+
+ top-level:
2098+
+ - h5netcdf
2099+
+requirements:
2100+
+ run:
2101+
+ - h5py
2102+
+ - packaging
2103+
+source:
2104+
+ url: https://files.pythonhosted.org/packages/68/2d/63851081b19d1ccf245091255797cb358c53c886609b5056da5457f7dbbf/h5netcdf-1.3.0-py3-none-any.whl
2105+
+ sha256: f2df69dcd3665dc9c4d43eb6529dedd113b2508090d12ac973573305a8406465
2106+
+about:
2107+
+ home: "https://github.com/h5netcdf/h5netcdf"
2108+
+ PyPI: https://pypi.org/project/h5netcdf
2109+
+ summary: netCDF4 via h5py
2110+
+ license: BSD-3-Clause
20752111
diff --git a/packages/h5py/meta.yaml b/packages/h5py/meta.yaml
2076-
index 3e67ba26..0e4c7b3c 100644
2112+
index 3e67ba26..e3b3e76f 100644
20772113
--- a/packages/h5py/meta.yaml
20782114
+++ b/packages/h5py/meta.yaml
20792115
@@ -1,14 +1,19 @@
@@ -2092,7 +2128,7 @@ index 3e67ba26..0e4c7b3c 100644
20922128
- patches/0001-Fix-incompatible-pointer-type.patch
20932129
- patches/configure.patch
20942130
+about:
2095-
+ home: ""
2131+
+ home: https://github.com/h5py/h5py
20962132
+ PyPI: https://pypi.org/project/h5py
20972133
+ summary: Read and write HDF5 files from Python
20982134
+ license: BSD-3-Clause

0 commit comments

Comments
 (0)