Skip to content

Commit 76e303c

Browse files
authored
fix: 修复SSE请求返回的content-type判断逻辑 (#274)
1 parent 294f311 commit 76e303c

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

packages/basic/src/utils/create/sseRequester.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { fetchEventSource, EventSourceMessage } from "@microsoft/fetch-event-source";
2-
import { genBaseOptions } from "./index";
1+
import { fetchEventSource, EventSourceMessage } from '@microsoft/fetch-event-source';
2+
import { genBaseOptions } from './index';
33

44
const MAX_RETRY_TIME = 0;
5-
const EventStreamContentType = "text/event-stream";
5+
const EventStreamContentType = 'text/event-stream';
66

77
export const sseRequester = function (requestInfo) {
88
const { url, config = {} } = requestInfo;
@@ -39,8 +39,9 @@ export const sseRequester = function (requestInfo) {
3939
if (leftRetries < 0) {
4040
close();
4141
}
42-
const contentType = response.headers.get("content-type");
43-
if (contentType !== EventStreamContentType) {
42+
const contentType = response.headers.get('content-type');
43+
// content-type可能返回包含charset等信息,因此需要包含判断
44+
if (!contentType.includes(EventStreamContentType)) {
4445
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
4546
}
4647
},

0 commit comments

Comments
 (0)