Skip to content

Commit

Permalink
Apply cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kouta-kun committed Mar 25, 2024
1 parent d38f7ed commit faa7c8c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/filters/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ where
S: TryStream<Ok = Event> + Send + 'static,
S::Error: StdError + Send + Sync + 'static,
{
SseReply { event_stream, charset: None }
SseReply {
event_stream,
charset: None,
}
}

/// Server-sent events reply (with explicit charset)
Expand Down Expand Up @@ -400,13 +403,16 @@ where
S: TryStream<Ok = Event> + Send + 'static,
S::Error: StdError + Send + Sync + 'static,
{
SseReply { event_stream, charset: Some(charset) }
SseReply {
event_stream,
charset: Some(charset),
}
}

#[allow(missing_debug_implementations)]
struct SseReply<S> {
event_stream: S,
charset: Option<String>
charset: Option<String>,
}

impl<S> Reply for SseReply<S>
Expand All @@ -428,11 +434,16 @@ where

let mut res = Response::new(Body::wrap_stream(body_stream));
// Set appropriate content type
res.headers_mut()
.insert(CONTENT_TYPE, match self.charset {
res.headers_mut().insert(
CONTENT_TYPE,
match self.charset {
None => HeaderValue::from_static("text/event-stream"),
Some(charset) => HeaderValue::from_str(format!("text/event-stream; charset={}", charset).as_str()).expect("Invalid header value"),
});
Some(charset) => HeaderValue::from_str(
format!("text/event-stream; charset={}", charset).as_str(),
)
.expect("Invalid header value"),
},
);
// Disable response body caching
res.headers_mut()
.insert(CACHE_CONTROL, HeaderValue::from_static("no-cache"));
Expand Down

0 comments on commit faa7c8c

Please sign in to comment.