You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MIGRATION.md
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -85,3 +85,33 @@ The default reconnect timeout is now 3 seconds - up from 1 second in v1/v2. This
85
85
Redirect handling now matches Chrome/Safari. On disconnects, we will always reconnect to the _original_ URL. In v1/v2, only HTTP 307 would reconnect to the original, while 301 and 302 would both redirect to the _destination_.
86
86
87
87
While the _ideal_ behavior would be for 301 and 308 to reconnect to the redirect _destination_, and 302/307 to reconnect to the _original_ URL, this is not possible to do cross-platform (cross-origin requests in browsers do not allow reading location headers, and redirect handling will have to be done manually).
88
+
89
+
#### Strict checking of Content-Type header
90
+
91
+
The `Content-Type` header is now checked. It's value must be `text/event-stream` (or
92
+
`text/event-stream; charset=utf-8`), and the connection will be failed otherwise.
93
+
94
+
To maintain the previous behaviour, you can use the `fetch` option to override the
95
+
returned `Content-Type` header if your server does not send the required header:
96
+
97
+
```ts
98
+
const es =newEventSource('https://my-server.com/sse', {
99
+
fetch: async (input, init) => {
100
+
const response =awaitfetch(input, init)
101
+
102
+
if (response.headers.get('content-type').startsWith('text/event-stream')) {
103
+
// Valid header, forward response
104
+
returnresponse
105
+
}
106
+
107
+
// Server did not respond with the correct content-type - override it
0 commit comments