File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
lib/plugins/event_dispatcher Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 11/**
2- * Copyright 2016-2018, 2020-2021, Optimizely
2+ * Copyright 2016-2018, 2020-2021, 2024 Optimizely
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -51,19 +51,26 @@ export const dispatchEvent = function(
5151 } ,
5252 } ;
5353
54+ const reqWrapper : { req ?: http . ClientRequest } = { } ;
55+
5456 const requestCallback = function ( response ?: { statusCode : number } ) : void {
5557 if ( response && response . statusCode && response . statusCode >= 200 && response . statusCode < 400 ) {
5658 callback ( response ) ;
5759 }
60+ reqWrapper . req ?. destroy ( ) ;
61+ reqWrapper . req = undefined ;
5862 } ;
5963
60- const req = ( parsedUrl . protocol === 'http:' ? http : https )
64+ reqWrapper . req = ( parsedUrl . protocol === 'http:' ? http : https )
6165 . request ( requestOptions , requestCallback as ( res : http . IncomingMessage ) => void ) ;
6266 // Add no-op error listener to prevent this from throwing
63- req . on ( 'error' , function ( ) { } ) ;
64- req . write ( dataString ) ;
65- req . end ( ) ;
66- return req ;
67+ reqWrapper . req . on ( 'error' , function ( ) {
68+ reqWrapper . req ?. destroy ( ) ;
69+ reqWrapper . req = undefined ;
70+ } ) ;
71+ reqWrapper . req . write ( dataString ) ;
72+ reqWrapper . req . end ( ) ;
73+ return reqWrapper . req ;
6774} ;
6875
6976export default {
You can’t perform that action at this time.
0 commit comments