@@ -28,6 +28,8 @@ export interface FetchEventSourceInit extends RequestInit {
28
28
/**
29
29
* Called when a response finishes. If you don't expect the server to kill
30
30
* the connection, you can throw an exception here and retry using onerror.
31
+ *
32
+ * For GET requests, default is retry.
31
33
*/
32
34
onclose ?: ( ) => void ;
33
35
@@ -44,8 +46,8 @@ export interface FetchEventSourceInit extends RequestInit {
44
46
45
47
/**
46
48
* 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.
49
51
*/
50
52
openWhenHidden ?: boolean ;
51
53
@@ -54,6 +56,7 @@ export interface FetchEventSourceInit extends RequestInit {
54
56
}
55
57
56
58
export function fetchEventSource ( input : RequestInfo , {
59
+ method : str ,
57
60
signal : inputSignal ,
58
61
headers : inputHeaders ,
59
62
onopen : inputOnOpen ,
@@ -65,6 +68,16 @@ export function fetchEventSource(input: RequestInfo, {
65
68
...rest
66
69
} : FetchEventSourceInit ) {
67
70
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
+ }
68
81
// make a copy of the input headers since we may modify it below:
69
82
const headers = { ...inputHeaders } ;
70
83
if ( ! headers . accept ) {
0 commit comments