Skip to content

Commit da6b90d

Browse files
committed
Do not retry non-GET requests by default
1 parent a052949 commit da6b90d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/fetch.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export interface FetchEventSourceInit extends RequestInit {
2828
/**
2929
* Called when a response finishes. If you don't expect the server to kill
3030
* the connection, you can throw an exception here and retry using onerror.
31+
*
32+
* For GET requests, default is retry.
3133
*/
3234
onclose?: () => void;
3335

@@ -44,8 +46,8 @@ export interface FetchEventSourceInit extends RequestInit {
4446

4547
/**
4648
* If true, will keep the request open even if the document is hidden.
47-
* By default, fetchEventSource will close the request and reopen it
48-
* automatically when the document becomes visible again.
49+
* By default for GET requests, fetchEventSource will close the request and
50+
* reopen it automatically when the document becomes visible again.
4951
*/
5052
openWhenHidden?: boolean;
5153

@@ -54,6 +56,7 @@ export interface FetchEventSourceInit extends RequestInit {
5456
}
5557

5658
export function fetchEventSource(input: RequestInfo, {
59+
method: str,
5760
signal: inputSignal,
5861
headers: inputHeaders,
5962
onopen: inputOnOpen,
@@ -65,6 +68,16 @@ export function fetchEventSource(input: RequestInfo, {
6568
...rest
6669
}: FetchEventSourceInit) {
6770
return new Promise<void>((resolve, reject) => {
71+
if (method != null && method !== 'GET') {
72+
// non GET requests modify server state, don't reset them
73+
// automatically
74+
if (onerror == null) {
75+
onerror = (e) { throw e; }
76+
}
77+
if (openWhenHidden == null) {
78+
openWhenHidden = true;
79+
}
80+
}
6881
// make a copy of the input headers since we may modify it below:
6982
const headers = { ...inputHeaders };
7083
if (!headers.accept) {

0 commit comments

Comments
 (0)