@@ -33,14 +33,6 @@ public SpaProxyLaunchManager(
33
33
34
34
public void StartInBackground ( CancellationToken cancellationToken )
35
35
{
36
- var httpClient = new HttpClient ( new HttpClientHandler ( )
37
- {
38
- // It's ok for us to do this here since this service is only plugged in during development.
39
- ServerCertificateCustomValidationCallback = HttpClientHandler . DangerousAcceptAnyServerCertificateValidator
40
- } ) ;
41
- // Certain frontend build tools rely on the the ACCEPT Header being set, otherwise these tools
42
- // might be unable to perform their client-side fallback logic.
43
- httpClient . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "*/*" ) ) ;
44
36
_logger . LogInformation ( $ "No SPA development server running at { _options . ServerUrl } found.") ;
45
37
46
38
// We are not waiting for the SPA proxy to launch, instead we are going to rely on a piece of
@@ -53,7 +45,7 @@ public void StartInBackground(CancellationToken cancellationToken)
53
45
{
54
46
if ( _launchTask == null )
55
47
{
56
- _launchTask = UpdateStatus ( StartSpaProcessAndProbeForLiveness ( httpClient , cancellationToken ) ) ;
48
+ _launchTask = UpdateStatus ( StartSpaProcessAndProbeForLiveness ( cancellationToken ) ) ;
57
49
}
58
50
}
59
51
@@ -79,11 +71,7 @@ async Task UpdateStatus(Task launchTask)
79
71
80
72
public async Task < bool > IsSpaProxyRunning ( CancellationToken cancellationToken )
81
73
{
82
- var httpClient = new HttpClient ( new HttpClientHandler ( )
83
- {
84
- // It's ok for us to do this here since this service is only plugged in during development.
85
- ServerCertificateCustomValidationCallback = HttpClientHandler . DangerousAcceptAnyServerCertificateValidator
86
- } ) ;
74
+ var httpClient = CreateHttpClient ( ) ;
87
75
88
76
using var timeout = new CancellationTokenSource ( TimeSpan . FromSeconds ( 10 ) ) ;
89
77
using var cancellationTokenSource = CancellationTokenSource . CreateLinkedTokenSource ( timeout . Token , cancellationToken ) ;
@@ -102,6 +90,18 @@ exception is TaskCanceledException ||
102
90
}
103
91
}
104
92
93
+ private static HttpClient CreateHttpClient ( )
94
+ {
95
+ var httpClient = new HttpClient ( new HttpClientHandler ( )
96
+ {
97
+ // It's ok for us to do this here since this service is only plugged in during development.
98
+ ServerCertificateCustomValidationCallback = HttpClientHandler . DangerousAcceptAnyServerCertificateValidator
99
+ } ) ;
100
+ // We don't care about the returned content type as long as the server is able to answer with 2XX
101
+ httpClient . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "*/*" , 0.1 ) ) ;
102
+ return httpClient ;
103
+ }
104
+
105
105
private async Task < bool > ProbeSpaDevelopmentServerUrl ( HttpClient httpClient , CancellationToken cancellationToken )
106
106
{
107
107
using var timeout = new CancellationTokenSource ( TimeSpan . FromSeconds ( 10 ) ) ;
@@ -121,12 +121,13 @@ exception is TaskCanceledException ||
121
121
}
122
122
}
123
123
124
- private async Task StartSpaProcessAndProbeForLiveness ( HttpClient httpClient , CancellationToken cancellationToken )
124
+ private async Task StartSpaProcessAndProbeForLiveness ( CancellationToken cancellationToken )
125
125
{
126
126
LaunchDevelopmentProxy ( ) ;
127
127
var sw = Stopwatch . StartNew ( ) ;
128
128
var livenessProbeSucceeded = false ;
129
129
var maxTimeoutReached = false ;
130
+ var httpClient = CreateHttpClient ( ) ;
130
131
while ( _spaProcess != null && ! _spaProcess . HasExited && ! maxTimeoutReached )
131
132
{
132
133
livenessProbeSucceeded = await ProbeSpaDevelopmentServerUrl ( httpClient , cancellationToken ) ;
0 commit comments