Skip to content

Commit deed3d7

Browse files
committed
sse: fix regression in URL joining
This was broken by #197. The URL join behaves like this: ``` $ let baseUrl = "https://example.com/sse"; $ new URL("?sessionId=x", baseUrl).href 'https://example.com/sse?sessionId=x' $ new URL("/?sessionId=x", baseUrl).href 'https://example.com/?sessionId=x' ``` The PR #197 did not take into account the relative URL Fixes #252
1 parent d1884fe commit deed3d7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/rmcp/src/transport/sse_client.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,20 @@ impl<C: SseClient> SseClientTransport<C> {
132132
let Some("endpoint") = sse.event.as_deref() else {
133133
continue;
134134
};
135-
let sse_endpoint = sse.data.unwrap_or_default();
135+
let ep = sse.data.unwrap_or_default();
136+
// Join the result and
137+
let sse_endpoint = if ep.starts_with("/") {
138+
// Absolute path, take as-is
139+
ep
140+
} else {
141+
// Relative path, merge with base
142+
sse_endpoint
143+
.path_and_query()
144+
.map(|p| p.path())
145+
.unwrap_or_default()
146+
.to_string()
147+
+ ep.as_str()
148+
};
136149
break sse_endpoint.parse::<http::Uri>()?;
137150
}
138151
};

0 commit comments

Comments
 (0)