|
8 | 8 | import httpx |
9 | 9 |
|
10 | 10 | from reflex.utils.decorator import once |
| 11 | +from reflex.utils.types import Unset |
11 | 12 |
|
12 | 13 | from . import console |
13 | 14 |
|
@@ -63,6 +64,30 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _T: |
63 | 64 | return wrapper |
64 | 65 |
|
65 | 66 |
|
| 67 | +def _wrap_https_lazy_func( |
| 68 | + func: Callable[[], Callable[_P, _T]], |
| 69 | +) -> Callable[_P, _T]: |
| 70 | + """Wrap an HTTPS function with logging. |
| 71 | +
|
| 72 | + Args: |
| 73 | + func: The function to wrap. |
| 74 | +
|
| 75 | + Returns: |
| 76 | + The wrapped function. |
| 77 | + """ |
| 78 | + unset = Unset() |
| 79 | + f: Callable[_P, _T] | Unset = unset |
| 80 | + |
| 81 | + def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _T: |
| 82 | + nonlocal f |
| 83 | + if isinstance(f, Unset): |
| 84 | + f = _wrap_https_func(func()) |
| 85 | + functools.update_wrapper(wrapper, f) |
| 86 | + return f(*args, **kwargs) |
| 87 | + |
| 88 | + return wrapper |
| 89 | + |
| 90 | + |
66 | 91 | def _is_ipv4_supported() -> bool: |
67 | 92 | """Determine if the system supports IPv4. |
68 | 93 |
|
@@ -120,12 +145,20 @@ def _httpx_client() -> httpx.Client: |
120 | 145 | Returns: |
121 | 146 | An HTTPX client. |
122 | 147 | """ |
| 148 | + from httpx._utils import get_environment_proxies |
| 149 | + |
123 | 150 | return httpx.Client( |
124 | 151 | transport=httpx.HTTPTransport( |
125 | 152 | local_address=_httpx_local_address_kwarg(), |
126 | 153 | verify=_httpx_verify_kwarg(), |
127 | | - ) |
| 154 | + ), |
| 155 | + mounts={ |
| 156 | + key: ( |
| 157 | + None if url is None else httpx.HTTPTransport(proxy=httpx.Proxy(url=url)) |
| 158 | + ) |
| 159 | + for key, url in get_environment_proxies().items() |
| 160 | + }, |
128 | 161 | ) |
129 | 162 |
|
130 | 163 |
|
131 | | -get = _wrap_https_func(_httpx_client().get) |
| 164 | +get = _wrap_https_lazy_func(lambda: _httpx_client().get) |
0 commit comments