Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(network): add http sse method (#2358)
Wenzhao Hua87c44a45015
diff --git a/packages/network/src/services/http/http.service.ts b/packages/network/src/services/http/http.service.tsindex 7399977b85..29baf17dd9 100644--- a/packages/network/src/services/http/http.service.ts+++ b/packages/network/src/services/http/http.service.ts@@ -114,6 +114,29 @@ export class HTTPService extends Disposable {return this._request<T>('PATCH', url, options);}+ getSSE<T>(+ method: HTTPRequestMethod,+ url: string,+ options?: IRequestParams+ ): Observable<HTTPEvent<T>> {+ // Things to do when sending a HTTP request:+ // 1. Generate HTTPRequest/HTTPHeader object+ // 2. Call interceptors and finally the HTTP implementation.+ const headers = new HTTPHeaders(options?.headers);+ const params = new HTTPParams(options?.params);+ const request = new HTTPRequest(method, url, {+ headers,+ params,+ withCredentials: options?.withCredentials ?? false, // default value for withCredentials is false by MDN+ responseType: options?.responseType ?? 'json',+ body: (['GET', 'DELETE'].includes(method)) ? undefined : (options as IPostRequestParams)?.body,+ });++ return of(request).pipe(+ concatMap((request) => this._runInterceptorsAndImplementation(request))+ );+ }+/** The HTTP request implementations */private async _request<T>(method: HTTPRequestMethod,diff --git a/packages/network/src/services/http/implementations/xhr.ts b/packages/network/src/services/http/implementations/xhr.tsindex e1da3b47e0..cd01217ac3 100644--- a/packages/network/src/services/http/implementations/xhr.ts+++ b/packages/network/src/services/http/implementations/xhr.ts@@ -103,8 +103,7 @@ export class XHRHTTPImplementation implements IHTTPImplementation {}));} else {- // next http error here- observer.next(+ observer.error(new HTTPResponseError({error,headers,@@ -124,7 +123,7 @@ export class XHRHTTPImplementation implements IHTTPImplementation {headers: buildResponseHeader().headers,});- observer.next(res);+ observer.error(res);};xhr.addEventListener('load', onLoadHandler);