mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-30 01:08:33 +00:00
* build(rust): upgrade reqwest to 0.13 and move MCP out of litellm-http The workspace moves to reqwest 0.13, so litellm-http no longer carries a second reqwest just for rmcp. The mcp feature, its pool and its proxy conversion go away, and the gateway hands rmcp a pooled NoRedirect client that already carries the TLS, proxy and timeout settings The Client test helpers collapse into for_test, a no-redirect client without TLS or proxy settings, and wrap_for_test for the few tests that need a hand-built reqwest client Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * build(deps): refresh compatible dependencies flagged by OSV * refactor(rust): remove redundant client construction comment * test(rust): cover configured MCP proxy and CA bundle --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
87 lines
2.7 KiB
Rust
87 lines
2.7 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use std::{
|
|
collections::HashMap,
|
|
sync::{Arc, Mutex},
|
|
};
|
|
|
|
use litellm_cache::JsonCodec;
|
|
use litellm_cache_gcs::{GcsCache, GcsConfig, StaticTokenSource, TokenSource};
|
|
use percent_encoding::percent_decode_str;
|
|
use serde_json::Value;
|
|
use wiremock::{Mock, MockServer, Request, Respond, ResponseTemplate, http::Method, matchers::any};
|
|
|
|
pub type JsonGcsCache = GcsCache<JsonCodec<Value>>;
|
|
|
|
pub fn config(server: &MockServer, gcs_path: Option<&str>) -> GcsConfig {
|
|
GcsConfig {
|
|
bucket_name: "bucket".into(),
|
|
gcs_path: gcs_path.map(str::to_string),
|
|
path_service_account: None,
|
|
endpoint: server.uri(),
|
|
}
|
|
}
|
|
|
|
pub fn cache_with_token(
|
|
server: &MockServer,
|
|
gcs_path: Option<&str>,
|
|
token: Arc<dyn TokenSource>,
|
|
) -> JsonGcsCache {
|
|
GcsCache::with_token_source(
|
|
config(server, gcs_path),
|
|
litellm_http::Client::for_test(),
|
|
JsonCodec::new(),
|
|
token,
|
|
)
|
|
}
|
|
|
|
pub fn cache(server: &MockServer, gcs_path: Option<&str>) -> JsonGcsCache {
|
|
cache_with_token(server, gcs_path, Arc::new(StaticTokenSource("tok".into())))
|
|
}
|
|
|
|
/// An in-memory bucket speaking the JSON API's media upload and `alt=media` download.
|
|
#[derive(Clone, Default)]
|
|
pub struct FakeBucket {
|
|
objects: Arc<Mutex<HashMap<String, Vec<u8>>>>,
|
|
}
|
|
|
|
impl FakeBucket {
|
|
pub async fn serve() -> MockServer {
|
|
let server = MockServer::start().await;
|
|
Mock::given(any())
|
|
.respond_with(Self::default())
|
|
.mount(&server)
|
|
.await;
|
|
server
|
|
}
|
|
}
|
|
|
|
impl Respond for FakeBucket {
|
|
fn respond(&self, request: &Request) -> ResponseTemplate {
|
|
let mut objects = self.objects.lock().unwrap();
|
|
match request.method {
|
|
Method::POST => {
|
|
let name = request
|
|
.url
|
|
.query_pairs()
|
|
.find_map(|(key, value)| (key == "name").then(|| value.into_owned()))
|
|
.expect("uploads carry the object name");
|
|
objects.insert(name, request.body.clone());
|
|
ResponseTemplate::new(200)
|
|
}
|
|
Method::GET => {
|
|
let encoded = request
|
|
.url
|
|
.path()
|
|
.strip_prefix("/storage/v1/b/bucket/o/")
|
|
.expect("downloads address an object");
|
|
let name = percent_decode_str(encoded).decode_utf8().unwrap();
|
|
match objects.get(name.as_ref()) {
|
|
Some(body) => ResponseTemplate::new(200).set_body_bytes(body.clone()),
|
|
None => ResponseTemplate::new(404),
|
|
}
|
|
}
|
|
_ => ResponseTemplate::new(405),
|
|
}
|
|
}
|
|
}
|