@@ -31,8 +31,8 @@ import {
31
31
import { RequestInfo } from './requestinfo' ;
32
32
import { isJustDef } from './type' ;
33
33
import { makeQueryString } from './url' ;
34
- import { Headers , XhrIo , ErrorCode } from './xhrio ' ;
35
- import { XhrIoPool } from './xhriopool ' ;
34
+ import { Headers , Connection , ErrorCode } from './connection ' ;
35
+ import { ConnectionPool } from './connectionPool ' ;
36
36
37
37
export interface Request < T > {
38
38
getPromise ( ) : Promise < T > ;
@@ -54,20 +54,20 @@ class NetworkRequest<T> implements Request<T> {
54
54
private body_ : string | Blob | Uint8Array | null ;
55
55
private successCodes_ : number [ ] ;
56
56
private additionalRetryCodes_ : number [ ] ;
57
- private pendingXhr_ : XhrIo | null = null ;
57
+ private pendingConnection_ : Connection | null = null ;
58
58
private backoffId_ : backoffId | null = null ;
59
59
private resolve_ ! : ( value ?: T | PromiseLike < T > ) => void ;
60
60
// eslint-disable-next-line @typescript-eslint/no-explicit-any
61
61
private reject_ ! : ( reason ?: any ) => void ;
62
62
private canceled_ : boolean = false ;
63
63
private appDelete_ : boolean = false ;
64
- private callback_ : ( p1 : XhrIo , p2 : string ) => T ;
64
+ private callback_ : ( p1 : Connection , p2 : string ) => T ;
65
65
private errorCallback_ :
66
- | ( ( p1 : XhrIo , p2 : FirebaseStorageError ) => FirebaseStorageError )
66
+ | ( ( p1 : Connection , p2 : FirebaseStorageError ) => FirebaseStorageError )
67
67
| null ;
68
68
private progressCallback_ : ( ( p1 : number , p2 : number ) => void ) | null ;
69
69
private timeout_ : number ;
70
- private pool_ : XhrIoPool ;
70
+ private pool_ : ConnectionPool ;
71
71
promise_ : Promise < T > ;
72
72
73
73
constructor (
@@ -77,13 +77,13 @@ class NetworkRequest<T> implements Request<T> {
77
77
body : string | Blob | Uint8Array | null ,
78
78
successCodes : number [ ] ,
79
79
additionalRetryCodes : number [ ] ,
80
- callback : ( p1 : XhrIo , p2 : string ) => T ,
80
+ callback : ( p1 : Connection , p2 : string ) => T ,
81
81
errorCallback :
82
- | ( ( p1 : XhrIo , p2 : FirebaseStorageError ) => FirebaseStorageError )
82
+ | ( ( p1 : Connection , p2 : FirebaseStorageError ) => FirebaseStorageError )
83
83
| null ,
84
84
timeout : number ,
85
85
progressCallback : ( ( p1 : number , p2 : number ) => void ) | null ,
86
- pool : XhrIoPool
86
+ pool : ConnectionPool
87
87
) {
88
88
this . url_ = url ;
89
89
this . method_ = method ;
@@ -117,8 +117,8 @@ class NetworkRequest<T> implements Request<T> {
117
117
backoffCallback ( false , new RequestEndStatus ( false , null , true ) ) ;
118
118
return ;
119
119
}
120
- const xhr = self . pool_ . createXhrIo ( ) ;
121
- self . pendingXhr_ = xhr ;
120
+ const connection = self . pool_ . createConnection ( ) ;
121
+ self . pendingConnection_ = connection ;
122
122
123
123
function progressListener ( progressEvent : ProgressEvent ) : void {
124
124
const loaded = progressEvent . loaded ;
@@ -128,28 +128,30 @@ class NetworkRequest<T> implements Request<T> {
128
128
}
129
129
}
130
130
if ( self . progressCallback_ !== null ) {
131
- xhr . addUploadProgressListener ( progressListener ) ;
131
+ connection . addUploadProgressListener ( progressListener ) ;
132
132
}
133
133
134
134
// eslint-disable-next-line @typescript-eslint/no-floating-promises
135
- xhr . send ( self . url_ , self . method_ , self . body_ , self . headers_ ) . then ( ( ) => {
136
- if ( self . progressCallback_ !== null ) {
137
- xhr . removeUploadProgressListener ( progressListener ) ;
138
- }
139
- self . pendingXhr_ = null ;
140
- const hitServer = xhr . getErrorCode ( ) === ErrorCode . NO_ERROR ;
141
- const status = xhr . getStatus ( ) ;
142
- if ( ! hitServer || self . isRetryStatusCode_ ( status ) ) {
143
- const wasCanceled = xhr . getErrorCode ( ) === ErrorCode . ABORT ;
144
- backoffCallback (
145
- false ,
146
- new RequestEndStatus ( false , null , wasCanceled )
147
- ) ;
148
- return ;
149
- }
150
- const successCode = self . successCodes_ . indexOf ( status ) !== - 1 ;
151
- backoffCallback ( true , new RequestEndStatus ( successCode , xhr ) ) ;
152
- } ) ;
135
+ connection
136
+ . send ( self . url_ , self . method_ , self . body_ , self . headers_ )
137
+ . then ( ( ) => {
138
+ if ( self . progressCallback_ !== null ) {
139
+ connection . removeUploadProgressListener ( progressListener ) ;
140
+ }
141
+ self . pendingConnection_ = null ;
142
+ const hitServer = connection . getErrorCode ( ) === ErrorCode . NO_ERROR ;
143
+ const status = connection . getStatus ( ) ;
144
+ if ( ! hitServer || self . isRetryStatusCode_ ( status ) ) {
145
+ const wasCanceled = connection . getErrorCode ( ) === ErrorCode . ABORT ;
146
+ backoffCallback (
147
+ false ,
148
+ new RequestEndStatus ( false , null , wasCanceled )
149
+ ) ;
150
+ return ;
151
+ }
152
+ const successCode = self . successCodes_ . indexOf ( status ) !== - 1 ;
153
+ backoffCallback ( true , new RequestEndStatus ( successCode , connection ) ) ;
154
+ } ) ;
153
155
}
154
156
155
157
/**
@@ -162,10 +164,13 @@ class NetworkRequest<T> implements Request<T> {
162
164
) : void {
163
165
const resolve = self . resolve_ ;
164
166
const reject = self . reject_ ;
165
- const xhr = status . xhr as XhrIo ;
167
+ const connection = status . connection as Connection ;
166
168
if ( status . wasSuccessCode ) {
167
169
try {
168
- const result = self . callback_ ( xhr , xhr . getResponseText ( ) ) ;
170
+ const result = self . callback_ (
171
+ connection ,
172
+ connection . getResponseText ( )
173
+ ) ;
169
174
if ( isJustDef ( result ) ) {
170
175
resolve ( result ) ;
171
176
} else {
@@ -175,11 +180,11 @@ class NetworkRequest<T> implements Request<T> {
175
180
reject ( e ) ;
176
181
}
177
182
} else {
178
- if ( xhr !== null ) {
183
+ if ( connection !== null ) {
179
184
const err = unknown ( ) ;
180
- err . serverResponse = xhr . getResponseText ( ) ;
185
+ err . serverResponse = connection . getResponseText ( ) ;
181
186
if ( self . errorCallback_ ) {
182
- reject ( self . errorCallback_ ( xhr , err ) ) ;
187
+ reject ( self . errorCallback_ ( connection , err ) ) ;
183
188
} else {
184
189
reject ( err ) ;
185
190
}
@@ -213,8 +218,8 @@ class NetworkRequest<T> implements Request<T> {
213
218
if ( this . backoffId_ !== null ) {
214
219
stop ( this . backoffId_ ) ;
215
220
}
216
- if ( this . pendingXhr_ !== null ) {
217
- this . pendingXhr_ . abort ( ) ;
221
+ if ( this . pendingConnection_ !== null ) {
222
+ this . pendingConnection_ . abort ( ) ;
218
223
}
219
224
}
220
225
@@ -247,7 +252,7 @@ export class RequestEndStatus {
247
252
248
253
constructor (
249
254
public wasSuccessCode : boolean ,
250
- public xhr : XhrIo | null ,
255
+ public connection : Connection | null ,
251
256
canceled ?: boolean
252
257
) {
253
258
this . canceled = ! ! canceled ;
@@ -291,7 +296,7 @@ export function makeRequest<T>(
291
296
appId : string | null ,
292
297
authToken : string | null ,
293
298
appCheckToken : string | null ,
294
- pool : XhrIoPool ,
299
+ pool : ConnectionPool ,
295
300
firebaseVersion ?: string
296
301
) : Request < T > {
297
302
const queryPart = makeQueryString ( requestInfo . urlParams ) ;
0 commit comments