Refactor to Pure Native JSON-RPC (Ditch SDKs)
This commit is contained in:
1 parent
5f0eba8a80
commit
f9dee11f32
9 files changed
+575
-1169
No files matched your search
+18
-7
@@ -20,16 +20,23 @@ fn run_proxy(target_url: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
let sse_url = format!("{}/sse", target_url);
|
||||
|
||||
eprintln!("[PROXY] Connecting to SSE: {}", sse_url);
|
||||
let resp = match client.get(&sse_url).send().await {
|
||||
eprintln!("[PROXY] Connecting to Streamable HTTP: {}", sse_url);
|
||||
let resp = match client.get(&sse_url)
|
||||
.header("Accept", "text/event-stream")
|
||||
.send().await {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
eprintln!("[PROXY] SSE connection failed: {}", e);
|
||||
eprintln!("[PROXY] Connection failed: {}", e);
|
||||
return Ok(true);
|
||||
}
|
||||
};
|
||||
|
||||
let post_url = Arc::new(RwLock::new(format!("{}/messages", target_url)));
|
||||
if resp.status() == reqwest::StatusCode::GONE {
|
||||
eprintln!("[PROXY] Streamable HTTP endpoint is gone.");
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
let post_url = Arc::new(RwLock::new(format!("{}/messages", target_url))); // Will be updated by endpoint event
|
||||
let post_url_clone = Arc::clone(&post_url);
|
||||
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel(1);
|
||||
@@ -62,7 +69,11 @@ fn run_proxy(target_url: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
url = url_arc.read().await.clone();
|
||||
}
|
||||
eprintln!("[PROXY] POSTing to {}", url);
|
||||
let res = client.post(&url).header("Content-Type", "application/json").body(body).send().await;
|
||||
let res = client.post(&url)
|
||||
.header("Accept", "application/json, text/event-stream")
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body)
|
||||
.send().await;
|
||||
eprintln!("[PROXY] POST response: {:?}", res.map(|r| r.status()));
|
||||
});
|
||||
}
|
||||
@@ -81,7 +92,7 @@ fn run_proxy(target_url: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
while let Ok(bytes) = reader.read_line(&mut line).await {
|
||||
if bytes == 0 { break; }
|
||||
let trimmed = line.trim();
|
||||
eprintln!("[PROXY] SSE read: {}", trimmed);
|
||||
eprintln!("[PROXY] Stream read: {}", trimmed);
|
||||
if trimmed.starts_with("event: message") {
|
||||
is_message = true;
|
||||
is_endpoint = false;
|
||||
@@ -102,7 +113,7 @@ fn run_proxy(target_url: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
}
|
||||
line.clear();
|
||||
}
|
||||
eprintln!("[PROXY] SSE stream closed");
|
||||
eprintln!("[PROXY] Stream closed");
|
||||
let _ = tx_clone2.send(true).await;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user