mirror of
https://github.com/tokio-rs/axum.git
synced 2025-10-01 15:00:46 +00:00
Add space between SSE field and value for compatibility (#2149)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
This commit is contained in:
parent
92ecbfc9b0
commit
0b7bf4b240
@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
- **added:** Implement `IntoResponse` for `(R,) where R: IntoResponse` ([#2143])
|
- **added:** Implement `IntoResponse` for `(R,) where R: IntoResponse` ([#2143])
|
||||||
|
- **changed:** For SSE, add space between field and value for compatibility ([#2149])
|
||||||
|
|
||||||
[#2143]: https://github.com/tokio-rs/axum/pull/2143
|
[#2143]: https://github.com/tokio-rs/axum/pull/2143
|
||||||
|
[#2149]: https://github.com/tokio-rs/axum/pull/2149
|
||||||
|
|
||||||
# 0.6.20 (03. August, 2023)
|
# 0.6.20 (03. August, 2023)
|
||||||
|
|
||||||
|
@ -171,9 +171,9 @@ pub struct Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Event {
|
impl Event {
|
||||||
/// Set the event's data data field(s) (`data:<content>`)
|
/// Set the event's data data field(s) (`data: <content>`)
|
||||||
///
|
///
|
||||||
/// Newlines in `data` will automatically be broken across `data:` fields.
|
/// Newlines in `data` will automatically be broken across `data: ` fields.
|
||||||
///
|
///
|
||||||
/// This corresponds to [`MessageEvent`'s data field].
|
/// This corresponds to [`MessageEvent`'s data field].
|
||||||
///
|
///
|
||||||
@ -202,7 +202,7 @@ impl Event {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the event's data field to a value serialized as unformatted JSON (`data:<content>`).
|
/// Set the event's data field to a value serialized as unformatted JSON (`data: <content>`).
|
||||||
///
|
///
|
||||||
/// This corresponds to [`MessageEvent`'s data field].
|
/// This corresponds to [`MessageEvent`'s data field].
|
||||||
///
|
///
|
||||||
@ -220,7 +220,7 @@ impl Event {
|
|||||||
panic!("Called `EventBuilder::json_data` multiple times");
|
panic!("Called `EventBuilder::json_data` multiple times");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.buffer.extend_from_slice(b"data:");
|
self.buffer.extend_from_slice(b"data: ");
|
||||||
serde_json::to_writer((&mut self.buffer).writer(), &data)?;
|
serde_json::to_writer((&mut self.buffer).writer(), &data)?;
|
||||||
self.buffer.put_u8(b'\n');
|
self.buffer.put_u8(b'\n');
|
||||||
|
|
||||||
@ -358,10 +358,7 @@ impl Event {
|
|||||||
);
|
);
|
||||||
self.buffer.extend_from_slice(name.as_bytes());
|
self.buffer.extend_from_slice(name.as_bytes());
|
||||||
self.buffer.put_u8(b':');
|
self.buffer.put_u8(b':');
|
||||||
// Prevent values that start with spaces having that space stripped
|
self.buffer.put_u8(b' ');
|
||||||
if value.starts_with(b" ") {
|
|
||||||
self.buffer.put_u8(b' ');
|
|
||||||
}
|
|
||||||
self.buffer.extend_from_slice(value);
|
self.buffer.extend_from_slice(value);
|
||||||
self.buffer.put_u8(b'\n');
|
self.buffer.put_u8(b'\n');
|
||||||
}
|
}
|
||||||
@ -516,7 +513,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn leading_space_is_not_stripped() {
|
fn leading_space_is_not_stripped() {
|
||||||
let no_leading_space = Event::default().data("\tfoobar");
|
let no_leading_space = Event::default().data("\tfoobar");
|
||||||
assert_eq!(&*no_leading_space.finalize(), b"data:\tfoobar\n\n");
|
assert_eq!(&*no_leading_space.finalize(), b"data: \tfoobar\n\n");
|
||||||
|
|
||||||
let leading_space = Event::default().data(" foobar");
|
let leading_space = Event::default().data(" foobar");
|
||||||
assert_eq!(&*leading_space.finalize(), b"data: foobar\n\n");
|
assert_eq!(&*leading_space.finalize(), b"data: foobar\n\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user