Skip to content

Commit 06b37fd

Browse files
committed
refactor(http): remove unreachable stream branches
1 parent f2c321c commit 06b37fd

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/builtins/runtime/http/sse.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,11 @@ impl HostStreamDriver for SseDriver {
475475
}
476476
}
477477
if self.eof_pending {
478-
if let Some(event) = self.parser.finish()?.into_iter().next() {
479-
return Poll::Ready(Ok(HostStreamPoll::Item(Self::event_value(event))));
480-
}
478+
// `finish` only validates and cleans up: it can surface a
479+
// partial BOM/UTF-8 or line-limit error, but it can never
480+
// dispatch an event because EventSource dispatch requires a
481+
// blank line and EOF discards a partial final event.
482+
self.parser.finish()?;
481483
self.eof_pending = false;
482484
self.state = DriverState::Closed;
483485
return Poll::Ready(Ok(HostStreamPoll::Item(map_value(vec![(
@@ -833,7 +835,14 @@ mod tests {
833835

834836
#[test]
835837
fn parser_rejects_malformed_and_incomplete_utf8() {
836-
for input in [b"data: \xff\n\n".as_slice(), b"data: \xc3".as_slice()] {
838+
for input in [
839+
b"data: \xff\n\n".as_slice(),
840+
b"data: \xc3".as_slice(),
841+
// A BOM prefix that never completes is still invalid UTF-8 and
842+
// must surface from `finish` at EOF instead of being dropped.
843+
b"\xef".as_slice(),
844+
b"\xef\xbb".as_slice(),
845+
] {
837846
assert!(
838847
parse_fragments(&[input], 64, 128, 256)
839848
.unwrap_err()

src/builtins/runtime/http/websocket.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,10 @@ impl HostStreamDriver for WebSocketDriver {
710710
_ => unreachable!(),
711711
};
712712
let result = self.poll_active(cx, &mut active);
713-
if matches!(self.state, DriverState::Finished) {
714-
if !matches!(result, Poll::Ready(Ok(HostStreamPoll::Complete(_)))) {
715-
self.state = DriverState::Active(active);
716-
}
717-
} else {
713+
// `poll_active` never touches `self.state`, which is
714+
// `Finished` here; restore it only when the active socket
715+
// must be resumed after a non-terminal poll.
716+
if !matches!(result, Poll::Ready(Ok(HostStreamPoll::Complete(_)))) {
718717
self.state = DriverState::Active(active);
719718
}
720719
return result;

0 commit comments

Comments
 (0)