Choose optimal relay strategy based on request type. - If relay_url_patterns are configured and the URL does NOT match, forward via SNI-rewrite HTTP (fast direct path). - GET requests for likely-large downloads use parallel-range relay. - All other requests go thro
(self, method, url, headers, body)
| 1255 | return b"".join(chunks) |
| 1256 | |
| 1257 | async def _relay_smart(self, method, url, headers, body): |
| 1258 | """Choose optimal relay strategy based on request type. |
| 1259 | |
| 1260 | - If relay_url_patterns are configured and the URL does NOT match, |
| 1261 | forward via SNI-rewrite HTTP (fast direct path). |
| 1262 | - GET requests for likely-large downloads use parallel-range relay. |
| 1263 | - All other requests go through the single-request relay. |
| 1264 | """ |
| 1265 | # Path-level relay routing: only matching URL prefixes go through relay; |
| 1266 | # everything else on the same host is forwarded via SNI-rewrite. |
| 1267 | if self._relay_url_patterns and not self._url_matches_relay_pattern(url): |
| 1268 | # Check if this host is one we pulled out of SNI-rewrite. |
| 1269 | stripped = re.sub(r'^https?://', '', url).lower() |
| 1270 | slash = stripped.find('/') |
| 1271 | req_host = stripped[:slash] if slash != -1 else stripped |
| 1272 | pattern_hosts = {p.split('/')[0] for p in self._relay_url_patterns} |
| 1273 | host_covered = any( |
| 1274 | req_host == h or req_host.endswith('.' + h) |
| 1275 | for h in pattern_hosts |
| 1276 | ) |
| 1277 | if host_covered: |
| 1278 | return await self._forward_via_sni_rewrite(method, url, headers, body) |
| 1279 | |
| 1280 | if method == "GET" and not body: |
| 1281 | # Respect client's own Range header verbatim. |
| 1282 | if header_value(headers, "range"): |
| 1283 | return await self.fronter.relay(method, url, headers, body) |
| 1284 | # Only probe with Range when the URL looks like a big file. |
| 1285 | if self._is_likely_download(url, headers): |
| 1286 | return await self.fronter.relay_parallel( |
| 1287 | method, |
| 1288 | url, |
| 1289 | headers, |
| 1290 | body, |
| 1291 | chunk_size=self._download_chunk_size, |
| 1292 | max_parallel=self._download_max_parallel, |
| 1293 | max_chunks=self._download_max_chunks, |
| 1294 | min_size=self._download_min_size, |
| 1295 | ) |
| 1296 | return await self.fronter.relay(method, url, headers, body) |
| 1297 | |
| 1298 | def _is_likely_download(self, url: str, headers: dict) -> bool: |
| 1299 | """Heuristic: is this URL likely a large file download?""" |
no test coverage detected