Skip to content

Commit 15720e0

Browse files
jokemanfireCopilot
andauthored
Update crates/rmcp/src/transport/streamable_http_server/tower.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8b58320 commit 15720e0

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • crates/rmcp/src/transport/streamable_http_server

crates/rmcp/src/transport/streamable_http_server/tower.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,26 @@ fn host_is_allowed(host: &NormalizedAuthority, allowed_hosts: &[String]) -> bool
209209
})
210210
}
211211

212+
fn bad_request_response(message: &str) -> BoxResponse {
213+
let body = Full::from(message.to_string()).boxed();
214+
215+
http::Response::builder()
216+
.status(http::StatusCode::BAD_REQUEST)
217+
.header(http::header::CONTENT_TYPE, "text/plain; charset=utf-8")
218+
.body(body)
219+
.expect("failed to build bad request response")
220+
}
221+
212222
fn parse_host_header(headers: &HeaderMap) -> Result<NormalizedAuthority, BoxResponse> {
213223
let Some(host) = headers.get(http::header::HOST) else {
214-
return Err(forbidden_response("Forbidden:missing_host header"));
224+
return Err(bad_request_response("Bad Request: missing Host header"));
215225
};
216226

217227
let host = host
218228
.to_str()
219-
.map_err(|_| forbidden_response("Forbidden: Invalid Host header encoding"))?;
229+
.map_err(|_| bad_request_response("Bad Request: Invalid Host header encoding"))?;
220230
let authority = http::uri::Authority::try_from(host)
221-
.map_err(|_| forbidden_response("Forbidden: Invalid Host header"))?;
231+
.map_err(|_| bad_request_response("Bad Request: Invalid Host header"))?;
222232
Ok(normalize_authority(authority.host(), authority.port_u16()))
223233
}
224234

0 commit comments

Comments
 (0)