@@ -94,9 +94,18 @@ public async Task<EsclJob> CreateScanJob(EsclScanSettings settings)
94
94
var response = await HttpClient . PostAsync ( url , content ) ;
95
95
response . EnsureSuccessStatusCode ( ) ;
96
96
Logger . LogDebug ( "POST OK" ) ;
97
+
98
+ // The job URI might not have our preferred ip/host; in particular, for IPv6 link-local addresses, it won't
99
+ // include the network interface.
100
+ var hostAndPort = GetHostAndPort ( ) ;
101
+ var uriBuilder = new UriBuilder ( response . Headers . Location ! )
102
+ {
103
+ Host = hostAndPort . Substring ( 0 , hostAndPort . LastIndexOf ( ":" , StringComparison . InvariantCulture ) )
104
+ } ;
105
+
97
106
return new EsclJob
98
107
{
99
- Uri = response . Headers . Location !
108
+ Uri = uriBuilder . Uri
100
109
} ;
101
110
}
102
111
@@ -177,14 +186,19 @@ private async Task<XDocument> DoRequest(string endpoint)
177
186
private string GetUrl ( string endpoint )
178
187
{
179
188
var protocol = _service . Tls || _service . Port == 443 ? "https" : "http" ;
180
- var ipAndPort = new IPEndPoint ( _service . RemoteEndpoint , _service . Port ) . ToString ( ) ;
189
+ return $ "{ protocol } ://{ GetHostAndPort ( ) } /{ _service . RootUrl } /{ endpoint } ";
190
+ }
191
+
192
+ private string GetHostAndPort ( )
193
+ {
194
+ var host = new IPEndPoint ( _service . RemoteEndpoint , _service . Port ) . ToString ( ) ;
181
195
#if NET6_0_OR_GREATER
182
196
if ( OperatingSystem . IsMacOS ( ) )
183
197
{
184
198
// Using the mDNS hostname is more reliable on Mac (but doesn't work at all on Windows)
185
- ipAndPort = $ "{ _service . Host } :{ _service . Port } ";
199
+ host = $ "{ _service . Host } :{ _service . Port } ";
186
200
}
187
201
#endif
188
- return $ " { protocol } :// { ipAndPort } / { _service . RootUrl } / { endpoint } " ;
202
+ return host ;
189
203
}
190
204
}
0 commit comments