@@ -148,36 +148,27 @@ export class Polling extends Transport {
148148 let buffer ;
149149 let offset = 0 ;
150150
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-
160151 const headers = {
161152 // text/html is required instead of text/plain to avoid an
162153 // unwanted download dialog on certain user-agents (GH-43)
163154 "Content-Type" : "text/html"
164155 } ;
165156
166157 this . headers ( req , headers ) ;
167- Object . keys ( headers ) . forEach ( key => {
158+ for ( let key in headers ) {
168159 res . writeHeader ( key , String ( headers [ key ] ) ) ;
169- } ) ;
160+ }
170161
171162 const onEnd = buffer => {
172163 this . onData ( buffer . toString ( ) ) ;
173-
174- if ( this . readyState !== "closing" ) {
175- res . end ( "ok" ) ;
176- }
177- cleanup ( ) ;
164+ this . onDataRequestCleanup ( ) ;
165+ res . end ( "ok" ) ;
178166 } ;
179167
180- res . onAborted ( onClose ) ;
168+ res . onAborted ( ( ) => {
169+ this . onDataRequestCleanup ( ) ;
170+ this . onError ( "data request connection closed prematurely" ) ;
171+ } ) ;
181172
182173 res . onData ( ( arrayBuffer , isLast ) => {
183174 const totalLength = offset + arrayBuffer . byteLength ;
@@ -201,7 +192,7 @@ export class Polling extends Transport {
201192 if ( totalLength != expectedContentLength ) {
202193 this . onError ( "content-length mismatch" ) ;
203194 res . writeStatus ( "400 Content-Length Mismatch" ) . end ( ) ;
204- cleanup ( ) ;
195+ this . onDataRequestCleanup ( ) ;
205196 return ;
206197 }
207198 onEnd ( buffer ) ;
@@ -212,6 +203,15 @@ export class Polling extends Transport {
212203 } ) ;
213204 }
214205
206+ /**
207+ * Cleanup request.
208+ *
209+ * @api private
210+ */
211+ private onDataRequestCleanup ( ) {
212+ this . dataReq = this . dataRes = null ;
213+ }
214+
215215 /**
216216 * Processes the incoming data payload.
217217 *
0 commit comments