Specify web proxy in SignalR connection building

Might solve https://github.com/ppy/osu/discussions/17897 (depends on how
adeptly signalr falls back to long polling if/when is fails to websocket
via the proxy, or maybe succeed).

As with the framework side change, I've tested this to not break a
zero-proxy flow. Intending to have the user test this after next
release.

Reference:
https://stackoverflow.com/questions/59343807/get-system-default-web-proxy-in-net-core
/
https://stackoverflow.com/questions/13515058/using-signalr-client-through-a-web-proxy
This commit is contained in:
Dean Herbert 2022-04-21 15:16:39 +09:00
parent 5c0e5eb6f4
commit e54d3702a6
1 changed files with 7 additions and 0 deletions

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Client;
@ -144,6 +145,12 @@ private HubConnection buildConnection(CancellationToken cancellationToken)
var builder = new HubConnectionBuilder()
.WithUrl(endpoint, options =>
{
// Use HttpClient.DefaultProxy once on net6 everywhere.
// The credential setter can also be removed at this point.
options.Proxy = WebRequest.DefaultWebProxy;
if (options.Proxy != null)
options.Proxy.Credentials = CredentialCache.DefaultCredentials;
options.Headers.Add("Authorization", $"Bearer {api.AccessToken}");
options.Headers.Add("OsuVersionHash", versionHash);
});