MCPcopy Create free account
hub / github.com/YougLin-dev/amp-server / handle_stream_response

Method handle_stream_response

api/src/proxy/service.rs:202–232  ·  view source on GitHub ↗
(
        response: reqwest::Response,
        config: &EndpointConfig,
    )

Source from the content-addressed store, hash-verified

200 }
201
202 async fn handle_stream_response(
203 response: reqwest::Response,
204 config: &EndpointConfig,
205 ) -> Result<Response, (StatusCode, String)> {
206 let status = response.status();
207 let headers = response.headers().clone();
208
209 let mut response_builder = Response::builder().status(status);
210
211 // Forward response headers
212 for header_name in &config.forward_response_headers {
213 if let Some(header_value) = headers.get(header_name) {
214 let name_str = header_name.as_str();
215 if !name_str.starts_with("connection") && !name_str.starts_with("transfer-encoding") {
216 response_builder = response_builder.header(header_name, header_value);
217 }
218 }
219 }
220
221 // Always forward as raw byte stream without parsing
222 let stream = response.bytes_stream().map(|result| {
223 result.map_err(std::io::Error::other)
224 });
225 let body = Body::from_stream(stream);
226
227 response_builder.body(body)
228 .map_err(|e| {
229 error!("Failed to build streaming response: {}", e);
230 (StatusCode::INTERNAL_SERVER_ERROR, "Failed to build streaming response".to_string())
231 })
232 }
233
234
235}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected