()
| 16834 | return this.#withCredentials; |
| 16835 | } |
| 16836 | #connect() { |
| 16837 | if (this.#readyState === CLOSED) return; |
| 16838 | this.#readyState = CONNECTING; |
| 16839 | const fetchParams = { |
| 16840 | request: this.#request, |
| 16841 | dispatcher: this.#dispatcher |
| 16842 | }; |
| 16843 | const processEventSourceEndOfBody = /* @__PURE__ */ __name((response) => { |
| 16844 | if (!isNetworkError(response)) { |
| 16845 | return this.#reconnect(); |
| 16846 | } |
| 16847 | }, "processEventSourceEndOfBody"); |
| 16848 | fetchParams.processResponseEndOfBody = processEventSourceEndOfBody; |
| 16849 | fetchParams.processResponse = (response) => { |
| 16850 | if (isNetworkError(response)) { |
| 16851 | if (response.aborted) { |
| 16852 | this.close(); |
| 16853 | this.dispatchEvent(new Event("error")); |
| 16854 | return; |
| 16855 | } else { |
| 16856 | this.#reconnect(); |
| 16857 | return; |
| 16858 | } |
| 16859 | } |
| 16860 | const contentType = response.headersList.get("content-type", true); |
| 16861 | const mimeType = contentType !== null ? parseMIMEType(contentType) : "failure"; |
| 16862 | const contentTypeValid = mimeType !== "failure" && mimeType.essence === "text/event-stream"; |
| 16863 | if (response.status !== 200 || contentTypeValid === false) { |
| 16864 | this.close(); |
| 16865 | this.dispatchEvent(new Event("error")); |
| 16866 | return; |
| 16867 | } |
| 16868 | this.#readyState = OPEN; |
| 16869 | this.dispatchEvent(new Event("open")); |
| 16870 | this.#state.origin = response.urlList[response.urlList.length - 1].origin; |
| 16871 | const eventSourceStream = new EventSourceStream({ |
| 16872 | eventSourceSettings: this.#state, |
| 16873 | push: /* @__PURE__ */ __name((event) => { |
| 16874 | this.dispatchEvent(createFastMessageEvent2( |
| 16875 | event.type, |
| 16876 | event.options |
| 16877 | )); |
| 16878 | }, "push") |
| 16879 | }); |
| 16880 | pipeline( |
| 16881 | response.body.stream, |
| 16882 | eventSourceStream, |
| 16883 | (error) => { |
| 16884 | if (error?.aborted === false) { |
| 16885 | this.close(); |
| 16886 | this.dispatchEvent(new Event("error")); |
| 16887 | } |
| 16888 | } |
| 16889 | ); |
| 16890 | }; |
| 16891 | this.#controller = fetching(fetchParams); |
| 16892 | } |
| 16893 | /** |
no test coverage detected