Decode server-sent events as UTF-8 and ignore a leading BOM
Closed
KL
4d ago+48+48+01234567890123456789-4-4-0123456789
Summary
A leading UTF-8 BOM made the first SSE event disappear, and a charset other than UTF-8 on text/event-stream garbled event data. The SSE spec says event streams are always UTF-8 and one leading BOM is ignored, which is what browsers do.
The SSE parser now reads bytes and decodes them with an incremental TextDecoder("utf-8-sig"), which handles both, including a BOM split across chunks. response.encoding is left untouched.
Checklist
- I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- I've updated the documentation accordingly.
AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.