@@ -148,36 +148,27 @@ export class Polling extends Transport {
148
148
let buffer ;
149
149
let offset = 0 ;
150
150
151
- const cleanup = ( ) => {
152
- this . dataReq = this . dataRes = null ;
153
- } ;
154
-
155
- const onClose = ( ) => {
156
- cleanup ( ) ;
157
- this . onError ( "data request connection closed prematurely" ) ;
158
- } ;
159
-
160
151
const headers = {
161
152
// text/html is required instead of text/plain to avoid an
162
153
// unwanted download dialog on certain user-agents (GH-43)
163
154
"Content-Type" : "text/html"
164
155
} ;
165
156
166
157
this . headers ( req , headers ) ;
167
- Object . keys ( headers ) . forEach ( key => {
158
+ for ( let key in headers ) {
168
159
res . writeHeader ( key , String ( headers [ key ] ) ) ;
169
- } ) ;
160
+ }
170
161
171
162
const onEnd = buffer => {
172
163
this . onData ( buffer . toString ( ) ) ;
173
-
174
- if ( this . readyState !== "closing" ) {
175
- res . end ( "ok" ) ;
176
- }
177
- cleanup ( ) ;
164
+ this . onDataRequestCleanup ( ) ;
165
+ res . end ( "ok" ) ;
178
166
} ;
179
167
180
- res . onAborted ( onClose ) ;
168
+ res . onAborted ( ( ) => {
169
+ this . onDataRequestCleanup ( ) ;
170
+ this . onError ( "data request connection closed prematurely" ) ;
171
+ } ) ;
181
172
182
173
res . onData ( ( arrayBuffer , isLast ) => {
183
174
const totalLength = offset + arrayBuffer . byteLength ;
@@ -201,7 +192,7 @@ export class Polling extends Transport {
201
192
if ( totalLength != expectedContentLength ) {
202
193
this . onError ( "content-length mismatch" ) ;
203
194
res . writeStatus ( "400 Content-Length Mismatch" ) . end ( ) ;
204
- cleanup ( ) ;
195
+ this . onDataRequestCleanup ( ) ;
205
196
return ;
206
197
}
207
198
onEnd ( buffer ) ;
@@ -212,6 +203,15 @@ export class Polling extends Transport {
212
203
} ) ;
213
204
}
214
205
206
+ /**
207
+ * Cleanup request.
208
+ *
209
+ * @api private
210
+ */
211
+ private onDataRequestCleanup ( ) {
212
+ this . dataReq = this . dataRes = null ;
213
+ }
214
+
215
215
/**
216
216
* Processes the incoming data payload.
217
217
*
0 commit comments