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