From 55fd8352e4d73ba77fe48897a11df9921e18e478 Mon Sep 17 00:00:00 2001 From: Eva Pace Date: Tue, 6 May 2025 01:38:03 -0300 Subject: [PATCH] assistant_slash_commands: Be more precise in content type matching (#29124) While investigating https://github.com/zed-industries/zed/issues/28076, I found out often times the content type header of a website comes with more data, such as the `charset`. So instead of doing an equal comparison, I changed to a `starts_with`. You can see an example here: ```shell $ curl -sS -D - https://github.com/zed-industries/zed/blob/main/Cargo.toml -o /dev/null | head -n 10 HTTP/2 200 date: Sun, 20 Apr 2025 10:19:52 GMT content-type: text/html; charset=utf-8 vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame,Accept-Encoding, Accept, X-Requested-With etag: W/"92dabf048b34d04a1b1d94e29cae4aca" cache-control: max-age=0, private, must-revalidate strict-transport-security: max-age=31536000; includeSubdomains; preload x-frame-options: deny x-content-type-options: nosniff x-xss-protection: 0 ``` Release Notes: - Improved Content Type matching of `/fetch` commands in Assistant Co-authored-by: Peter Tripp --- .../assistant_slash_commands/src/fetch_command.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/assistant_slash_commands/src/fetch_command.rs b/crates/assistant_slash_commands/src/fetch_command.rs index 6c1badeb74..2b98a21b6f 100644 --- a/crates/assistant_slash_commands/src/fetch_command.rs +++ b/crates/assistant_slash_commands/src/fetch_command.rs @@ -55,11 +55,14 @@ impl FetchSlashCommand { let content_type = content_type .to_str() .context("invalid Content-Type header")?; - let content_type = match content_type { - "text/html" => ContentType::Html, - "text/plain" => ContentType::Plaintext, - "application/json" => ContentType::Json, - _ => ContentType::Html, + let content_type = if content_type.starts_with("text/html") { + ContentType::Html + } else if content_type.starts_with("text/plain") { + ContentType::Plaintext + } else if content_type.starts_with("application/json") { + ContentType::Json + } else { + ContentType::Html }; match content_type {