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
+1 -1
View File
@@ -11,7 +11,7 @@ namespace VRCX
class ImageCache class ImageCache
{ {
private static readonly string cacheLocation = Path.Combine(Program.AppDataDirectory, "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 HttpClient httpClient = new HttpClient(httpClientHandler);
private static readonly List<string> _imageHosts = private static readonly List<string> _imageHosts =
[ [
+7
View File
@@ -6,6 +6,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Net;
using System.Reflection; using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using CefSharp; using CefSharp;
@@ -57,6 +58,12 @@ namespace VRCX
Dock = DockStyle.Fill Dock = DockStyle.Fill
}; };
string? proxyUrl = VRCXStorage.Instance.Get("VRCX_ProxyServer");
if (!string.IsNullOrEmpty(proxyUrl))
{
WebApi.Proxy = new WebProxy(proxyUrl);
}
Browser.IsBrowserInitializedChanged += (A, B) => Browser.IsBrowserInitializedChanged += (A, B) =>
{ {
if (Program.LaunchDebug) if (Program.LaunchDebug)
+2 -2
View File
@@ -155,9 +155,10 @@ namespace VRCX
private static void Run() private static void Run()
{ {
BrowserSubprocess.Start();
StartupArgs.ArgsCheck(); StartupArgs.ArgsCheck();
SetProgramDirectories(); SetProgramDirectories();
VRCXStorage.Load();
BrowserSubprocess.Start();
ConfigureLogger(); ConfigureLogger();
Update.Check(); Update.Check();
GetVersion(); GetVersion();
@@ -169,7 +170,6 @@ namespace VRCX
ProcessMonitor.Instance.Init(); ProcessMonitor.Instance.Init();
VRCXStorage.Load();
SQLiteLegacy.Instance.Init(); SQLiteLegacy.Instance.Init();
AppApi.Instance.Init(); AppApi.Instance.Init();
AppApiVr.Instance.Init(); AppApiVr.Instance.Init();
+6 -2
View File
@@ -5,6 +5,7 @@
// For a copy, see <https://opensource.org/licenses/MIT>. // For a copy, see <https://opensource.org/licenses/MIT>.
using CefSharp; using CefSharp;
using CefSharp.Internals;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@@ -17,7 +18,6 @@ namespace VRCX
{ {
internal class StartupArgs internal class StartupArgs
{ {
public static IWebProxy? Proxy = WebRequest.DefaultWebProxy;
public static string LaunchCommand; public static string LaunchCommand;
public static Process[] processList; public static Process[] processList;
@@ -54,10 +54,14 @@ namespace VRCX
if (arg.Length >= 16 && arg.Substring(0, 14) == "--proxy-server") if (arg.Length >= 16 && arg.Substring(0, 14) == "--proxy-server")
{ {
string proxyUrl = arg.Substring(15).Replace("'", string.Empty).Replace("\"", string.Empty); 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)) if (!string.IsNullOrEmpty(Program.AppDataDirectory))
disableClosing = true; // we're launching with a custom config path, allow it disableClosing = true; // we're launching with a custom config path, allow it
+5 -4
View File
@@ -19,6 +19,7 @@ namespace VRCX
public CookieContainer _cookieContainer; public CookieContainer _cookieContainer;
private bool _cookieDirty; private bool _cookieDirty;
private Timer _timer; private Timer _timer;
public static IWebProxy? Proxy = WebRequest.DefaultWebProxy;
static WebApi() static WebApi()
{ {
@@ -144,7 +145,7 @@ namespace VRCX
private static async Task LegacyImageUpload(HttpWebRequest request, IDictionary<string, object> options) private static async Task LegacyImageUpload(HttpWebRequest request, IDictionary<string, object> options)
{ {
request.Proxy = StartupArgs.Proxy; request.Proxy = Proxy;
request.Method = "POST"; request.Method = "POST";
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x"); string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
request.ContentType = "multipart/form-data; boundary=" + boundary; request.ContentType = "multipart/form-data; boundary=" + boundary;
@@ -189,7 +190,7 @@ namespace VRCX
private static async Task UploadFilePut(HttpWebRequest request, IDictionary<string, object> options) private static async Task UploadFilePut(HttpWebRequest request, IDictionary<string, object> options)
{ {
request.Proxy = StartupArgs.Proxy; request.Proxy = Proxy;
request.Method = "PUT"; request.Method = "PUT";
request.ContentType = options["fileMIME"] as string; request.ContentType = options["fileMIME"] as string;
var fileData = options["fileData"] 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) private static async Task ImageUpload(HttpWebRequest request, IDictionary<string, object> options)
{ {
request.Proxy = StartupArgs.Proxy; request.Proxy = Proxy;
request.Method = "POST"; request.Method = "POST";
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x"); string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
request.ContentType = "multipart/form-data; boundary=" + boundary; request.ContentType = "multipart/form-data; boundary=" + boundary;
@@ -258,7 +259,7 @@ namespace VRCX
try try
{ {
var request = WebRequest.CreateHttp((string)options["url"]); var request = WebRequest.CreateHttp((string)options["url"]);
request.Proxy = StartupArgs.Proxy; request.Proxy = Proxy;
request.CookieContainer = _cookieContainer; request.CookieContainer = _cookieContainer;
request.KeepAlive = true; request.KeepAlive = true;
request.UserAgent = Program.Version; request.UserAgent = Program.Version;