Add proxy from launch argument to WebApi

Co-authored-by: Nekromateion <43814053+Nekromateion@users.noreply.github.com>
This commit is contained in:
Natsumi
2024-07-17 06:42:33 +12:00
parent 8740905a08
commit a4d03c7e00
5 changed files with 21 additions and 9 deletions

View File

@@ -11,7 +11,7 @@ namespace VRCX
class ImageCache
{
private static readonly string cacheLocation = Path.Combine(Program.AppDataDirectory, "ImageCache");
private static readonly HttpClientHandler httpClientHandler = new HttpClientHandler(){ Proxy = StartupArgs.Proxy };
private static readonly HttpClientHandler httpClientHandler = new HttpClientHandler(){ Proxy = WebApi.Proxy };
private static readonly HttpClient httpClient = new HttpClient(httpClientHandler);
private static readonly List<string> _imageHosts =
[

View File

@@ -6,6 +6,7 @@
using System;
using System.Drawing;
using System.Net;
using System.Reflection;
using System.Windows.Forms;
using CefSharp;
@@ -57,6 +58,12 @@ namespace VRCX
Dock = DockStyle.Fill
};
string? proxyUrl = VRCXStorage.Instance.Get("VRCX_ProxyServer");
if (!string.IsNullOrEmpty(proxyUrl))
{
WebApi.Proxy = new WebProxy(proxyUrl);
}
Browser.IsBrowserInitializedChanged += (A, B) =>
{
if (Program.LaunchDebug)

View File

@@ -155,9 +155,10 @@ namespace VRCX
private static void Run()
{
BrowserSubprocess.Start();
StartupArgs.ArgsCheck();
SetProgramDirectories();
VRCXStorage.Load();
BrowserSubprocess.Start();
ConfigureLogger();
Update.Check();
GetVersion();
@@ -169,7 +170,6 @@ namespace VRCX
ProcessMonitor.Instance.Init();
VRCXStorage.Load();
SQLiteLegacy.Instance.Init();
AppApi.Instance.Init();
AppApiVr.Instance.Init();

View File

@@ -5,6 +5,7 @@
// For a copy, see <https://opensource.org/licenses/MIT>.
using CefSharp;
using CefSharp.Internals;
using System;
using System.Diagnostics;
using System.IO;
@@ -17,7 +18,6 @@ namespace VRCX
{
internal class StartupArgs
{
public static IWebProxy? Proxy = WebRequest.DefaultWebProxy;
public static string LaunchCommand;
public static Process[] processList;
@@ -54,10 +54,14 @@ namespace VRCX
if (arg.Length >= 16 && arg.Substring(0, 14) == "--proxy-server")
{
string proxyUrl = arg.Substring(15).Replace("'", string.Empty).Replace("\"", string.Empty);
Proxy = new WebProxy(proxyUrl);
WebApi.Proxy = new WebProxy(proxyUrl);
}
}
var type = CommandLineArgsParser.GetArgumentValue(args, CefSharpArguments.SubProcessTypeArgument);
if (!string.IsNullOrEmpty(type))
disableClosing = true; // we're launching a subprocess, allow it
if (!string.IsNullOrEmpty(Program.AppDataDirectory))
disableClosing = true; // we're launching with a custom config path, allow it

View File

@@ -19,6 +19,7 @@ namespace VRCX
public CookieContainer _cookieContainer;
private bool _cookieDirty;
private Timer _timer;
public static IWebProxy? Proxy = WebRequest.DefaultWebProxy;
static WebApi()
{
@@ -144,7 +145,7 @@ namespace VRCX
private static async Task LegacyImageUpload(HttpWebRequest request, IDictionary<string, object> options)
{
request.Proxy = StartupArgs.Proxy;
request.Proxy = Proxy;
request.Method = "POST";
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
request.ContentType = "multipart/form-data; boundary=" + boundary;
@@ -189,7 +190,7 @@ namespace VRCX
private static async Task UploadFilePut(HttpWebRequest request, IDictionary<string, object> options)
{
request.Proxy = StartupArgs.Proxy;
request.Proxy = Proxy;
request.Method = "PUT";
request.ContentType = options["fileMIME"] as string;
var fileData = options["fileData"] as string;
@@ -204,7 +205,7 @@ namespace VRCX
private static async Task ImageUpload(HttpWebRequest request, IDictionary<string, object> options)
{
request.Proxy = StartupArgs.Proxy;
request.Proxy = Proxy;
request.Method = "POST";
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
request.ContentType = "multipart/form-data; boundary=" + boundary;
@@ -258,7 +259,7 @@ namespace VRCX
try
{
var request = WebRequest.CreateHttp((string)options["url"]);
request.Proxy = StartupArgs.Proxy;
request.Proxy = Proxy;
request.CookieContainer = _cookieContainer;
request.KeepAlive = true;
request.UserAgent = Program.Version;