diff --git a/NAPS2.Escl/Client/EsclClient.cs b/NAPS2.Escl/Client/EsclClient.cs index 941f24be70..ddd8d5d332 100644 --- a/NAPS2.Escl/Client/EsclClient.cs +++ b/NAPS2.Escl/Client/EsclClient.cs @@ -94,9 +94,18 @@ public async Task CreateScanJob(EsclScanSettings settings) var response = await HttpClient.PostAsync(url, content); response.EnsureSuccessStatusCode(); Logger.LogDebug("POST OK"); + + // The job URI might not have our preferred ip/host; in particular, for IPv6 link-local addresses, it won't + // include the network interface. + var hostAndPort = GetHostAndPort(); + var uriBuilder = new UriBuilder(response.Headers.Location!) + { + Host = hostAndPort.Substring(0, hostAndPort.LastIndexOf(":", StringComparison.InvariantCulture)) + }; + return new EsclJob { - Uri = response.Headers.Location! + Uri = uriBuilder.Uri }; } @@ -177,14 +186,19 @@ private async Task DoRequest(string endpoint) private string GetUrl(string endpoint) { var protocol = _service.Tls || _service.Port == 443 ? "https" : "http"; - var ipAndPort = new IPEndPoint(_service.RemoteEndpoint, _service.Port).ToString(); + return $"{protocol}://{GetHostAndPort()}/{_service.RootUrl}/{endpoint}"; + } + + private string GetHostAndPort() + { + var host = new IPEndPoint(_service.RemoteEndpoint, _service.Port).ToString(); #if NET6_0_OR_GREATER if (OperatingSystem.IsMacOS()) { // Using the mDNS hostname is more reliable on Mac (but doesn't work at all on Windows) - ipAndPort = $"{_service.Host}:{_service.Port}"; + host = $"{_service.Host}:{_service.Port}"; } #endif - return $"{protocol}://{ipAndPort}/{_service.RootUrl}/{endpoint}"; + return host; } } \ No newline at end of file