Streaming variant of [`proxy_with_candidates`](Self::proxy_with_candidates). Returns response headers immediately without buffering the body. The caller streams body chunks via [`StreamingProxyResponse::response`].
(
&self,
source_protocol: &str,
method: &str,
path: &str,
headers: Vec<(String, String)>,
body: bytes::Bytes,
candidates: &[ResolvedRoute],
| 103 | /// Returns response headers immediately without buffering the body. |
| 104 | /// The caller streams body chunks via [`StreamingProxyResponse::response`]. |
| 105 | pub async fn proxy_with_candidates_streaming( |
| 106 | &self, |
| 107 | source_protocol: &str, |
| 108 | method: &str, |
| 109 | path: &str, |
| 110 | headers: Vec<(String, String)>, |
| 111 | body: bytes::Bytes, |
| 112 | candidates: &[ResolvedRoute], |
| 113 | ) -> Result<StreamingProxyResponse, RouterError> { |
| 114 | let normalized_source = source_protocol.trim().to_ascii_lowercase(); |
| 115 | let route = candidates |
| 116 | .iter() |
| 117 | .find(|r| r.protocols.iter().any(|p| p == &normalized_source)) |
| 118 | .ok_or_else(|| RouterError::NoCompatibleRoute(source_protocol.to_string()))?; |
| 119 | |
| 120 | info!( |
| 121 | protocols = %route.protocols.join(","), |
| 122 | endpoint = %route.endpoint, |
| 123 | method = %method, |
| 124 | path = %path, |
| 125 | "routing proxy inference request (streaming)" |
| 126 | ); |
| 127 | |
| 128 | if mock::is_mock_route(route) { |
| 129 | info!(endpoint = %route.endpoint, "returning mock response (buffered)"); |
| 130 | let buffered = mock::mock_response(route, &normalized_source); |
| 131 | return Ok(StreamingProxyResponse::from_buffered(buffered)); |
| 132 | } |
| 133 | |
| 134 | backend::proxy_to_backend_streaming( |
| 135 | &self.client, |
| 136 | route, |
| 137 | &normalized_source, |
| 138 | method, |
| 139 | path, |
| 140 | headers, |
| 141 | body, |
| 142 | ) |
| 143 | .await |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | #[cfg(test)] |