aiway_protocol/context/
response_ext.rs1use crate::common::header::Headers;
2use http::response::Parts;
3
4pub trait ResponseExt {
5 fn is_sse(&self) -> bool;
6 fn is_ws(&self) -> bool;
7}
8
9impl ResponseExt for Parts {
10 fn is_sse(&self) -> bool {
11 self.headers
12 .get(Headers::CONTENT_TYPE)
13 .and_then(|v| v.to_str().ok())
14 .map(|v| v.starts_with("text/event-stream"))
15 .unwrap_or(false)
16 }
17
18 fn is_ws(&self) -> bool {
19 self.headers
20 .get(Headers::UPGRADE)
21 .and_then(|v| v.to_str().ok())
22 .map(|v| v == "websocket")
23 .unwrap_or(false)
24 }
25}