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 <peter@zed.dev>
This commit is contained in:
parent
0b10eb7577
commit
55fd8352e4
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user