@@ -63,15 +63,17 @@ public async Task<KeyOperationResult> GetKeysAsync(string keyPath)
6363 try
6464 {
6565 CondenserEventSource . Log . ConfigurationGetKeysRecursive ( keyPath ) ;
66- var response = await _httpClient . GetAsync ( $ "{ ConsulKeyPath } { keyPath } ?recurse") ;
67- if ( ! response . IsSuccessStatusCode )
66+ using ( var response = await _httpClient . GetAsync ( $ "{ ConsulKeyPath } { keyPath } ?recurse") )
6867 {
69- _logger ? . LogWarning ( "We didn't get a succesful response from consul code was {code}" , response . StatusCode ) ;
70- return new KeyOperationResult ( ) { Success = false , Dictionary = null } ;
68+ if ( ! response . IsSuccessStatusCode )
69+ {
70+ _logger ? . LogWarning ( "We didn't get a succesful response from consul code was {code}" , response . StatusCode ) ;
71+ return new KeyOperationResult ( ) { Success = false , Dictionary = null } ;
72+ }
73+
74+ var dictionary = await BuildDictionaryAsync ( keyPath , response ) ;
75+ return new KeyOperationResult ( ) { Success = true , Dictionary = dictionary } ;
7176 }
72-
73- var dictionary = await BuildDictionaryAsync ( keyPath , response ) ;
74- return new KeyOperationResult ( ) { Success = true , Dictionary = dictionary } ;
7577 }
7678 catch ( Exception ex )
7779 {
@@ -86,17 +88,19 @@ public async Task<KeyOperationResult> GetKeysAsync(string keyPath)
8688 try
8789 {
8890 CondenserEventSource . Log . ConfigurationGetKey ( keyPath ) ;
89- var response = await _httpClient . GetAsync ( $ "{ ConsulKeyPath } { keyPath } ") ;
90- if ( ! response . IsSuccessStatusCode )
91+ using ( var response = await _httpClient . GetAsync ( $ "{ ConsulKeyPath } { keyPath } ") )
9192 {
92- _logger ? . LogWarning ( "We didn't get a successful response from consul code was {code}" , response . StatusCode ) ;
93- return ( false , null ) ;
93+ if ( ! response . IsSuccessStatusCode )
94+ {
95+ _logger ? . LogWarning ( "We didn't get a successful response from consul code was {code}" , response . StatusCode ) ;
96+ return ( false , null ) ;
97+ }
98+
99+ var content = await response . Content . ReadAsStringAsync ( ) ;
100+ var keys = JsonConvert . DeserializeObject < KeyValue [ ] > ( content ) ;
101+ if ( keys . Length != 1 ) return ( false , null ) ;
102+ return ( true , keys [ 0 ] . Value ) ;
94103 }
95-
96- var content = await response . Content . ReadAsStringAsync ( ) ;
97- var keys = JsonConvert . DeserializeObject < KeyValue [ ] > ( content ) ;
98- if ( keys . Length != 1 ) return ( false , null ) ;
99- return ( true , keys [ 0 ] . Value ) ;
100104 }
101105 catch ( Exception exception )
102106 {
@@ -113,23 +117,25 @@ public async Task<KeyOperationResult> TryWatchKeysAsync(string keyPath, object s
113117 try
114118 {
115119 CondenserEventSource . Log . ConfigurationWatchKey ( keyPath ) ;
116- var response = await _httpClient . GetAsync ( url + consulState . ConsulIndex , _disposed . Token ) ;
117- var newConsulIndex = response . GetConsulIndex ( ) ;
118-
119- if ( ! response . IsSuccessStatusCode )
120- {
121- consulState . ConsulIndex = newConsulIndex ;
122- return default ;
123- }
124-
125- if ( newConsulIndex == consulState . ConsulIndex )
120+ using ( var response = await _httpClient . GetAsync ( url + consulState . ConsulIndex , _disposed . Token ) )
126121 {
122+ var newConsulIndex = response . GetConsulIndex ( ) ;
123+
124+ if ( ! response . IsSuccessStatusCode )
125+ {
126+ consulState . ConsulIndex = newConsulIndex ;
127+ return default ;
128+ }
129+
130+ if ( newConsulIndex == consulState . ConsulIndex )
131+ {
132+ consulState . ConsulIndex = newConsulIndex ;
133+ return default ;
134+ }
127135 consulState . ConsulIndex = newConsulIndex ;
128- return default ;
136+ var dictionary = await BuildDictionaryAsync ( keyPath , response ) ;
137+ return new KeyOperationResult ( ) { Success = true , Dictionary = dictionary } ;
129138 }
130- consulState . ConsulIndex = newConsulIndex ;
131- var dictionary = await BuildDictionaryAsync ( keyPath , response ) ;
132- return new KeyOperationResult ( ) { Success = true , Dictionary = dictionary } ;
133139 }
134140 catch ( Exception ex )
135141 {
0 commit comments