File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525using MSStore . CLI . Services . CredentialManager ;
2626using MSStore . CLI . Services . ElectronManager ;
2727using MSStore . CLI . Services . Graph ;
28+ using MSStore . CLI . Services . Http ;
2829using MSStore . CLI . Services . PartnerCenter ;
2930using MSStore . CLI . Services . PWABuilder ;
3031using MSStore . CLI . Services . Telemetry ;
@@ -117,7 +118,7 @@ public static async Task<int> Main(params string[] args)
117118 } )
118119 . ConfigurePrimaryHttpMessageHandler ( ( ) =>
119120 {
120- return new HttpClientHandler
121+ return new RetryAfterHttpHandler
121122 {
122123 CheckCertificateRevocationList = true
123124 } ;
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation. All rights reserved.
2+ // Licensed under the MIT License.
3+
4+ using System . Linq ;
5+ using System . Net . Http ;
6+ using System . Threading ;
7+ using System . Threading . Tasks ;
8+
9+ namespace MSStore . CLI . Services . Http
10+ {
11+ public sealed class RetryAfterHttpHandler : HttpClientHandler
12+ {
13+ /// <inheritdoc/>
14+ protected override async Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken cancellationToken )
15+ {
16+ do
17+ {
18+ var httpResponse = await base . SendAsync ( request , cancellationToken ) ;
19+ if ( httpResponse . StatusCode == System . Net . HttpStatusCode . TooManyRequests )
20+ {
21+ if ( httpResponse . Headers . TryGetValues ( "Retry-After" , out var values ) )
22+ {
23+ var retryAfter = values . FirstOrDefault ( ) ;
24+ if ( int . TryParse ( retryAfter , out int delaySeconds ) )
25+ {
26+ await Task . Delay ( delaySeconds * 1000 , cancellationToken ) ;
27+ continue ;
28+ }
29+ }
30+ await Task . Delay ( 500 , cancellationToken ) ;
31+ continue ;
32+ }
33+ else
34+ {
35+ return httpResponse ;
36+ }
37+ }
38+ while ( true ) ;
39+ }
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments