diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs index 1e9ff46ea..91761b948 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs @@ -149,12 +149,12 @@ namespace System.Application.UI.ViewModels { if (s.Result == MessageBoxResultCompat.OK) { - var item = await DI.Get().AddScriptAsync(url, script); + var item = await DI.Get().AddScriptAsync(url, script,build: script.IsBuild,order:script.Order); if (item.state) { if (ProxyService.Current.ProxyScripts.Items.Any() && item.model != null) { - ProxyService.Current.ProxyScripts.Replace(script, item.model); + ProxyService.Current.ProxyScripts.Replace(script, item.model) ; } } } @@ -170,7 +170,7 @@ namespace System.Application.UI.ViewModels { if (script?.FilePath != null) { - var item = await DI.Get().AddScriptAsync(script.FilePath, build: script.IsBuild); + var item = await DI.Get().AddScriptAsync(Path.Combine(IOPath.AppDataDirectory, script.FilePath), build: script.IsBuild); if (item.state) if (item.model != null) { diff --git a/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs b/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs index 1a7990309..5f6944d7b 100644 --- a/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs @@ -6,11 +6,14 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; using System.Properties; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using Titanium.Web.Proxy; using Titanium.Web.Proxy.EventArguments; @@ -41,7 +44,6 @@ namespace System.Application.Services.Implementation public bool ProxyRunning => proxyServer.ProxyRunning; public IList JsHeader => new List() { new HttpHeader("Content-Type", "text/javascript;charset=UTF-8") }; - public HttpProxyServiceImpl() { //if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -60,7 +62,31 @@ namespace System.Application.Services.Implementation proxyServer.CertificateManager.RootCertificate = proxyServer.CertificateManager.LoadRootCertificate(); } - + public async Task HttpRequest(SessionEventArgs e) { + //IHttpService.Instance.SendAsync(); + var url = Web.HttpUtility.UrlDecode(e.HttpClient.Request.RequestUri.Query.Replace("?request=", "")); + var cancellationToken = new CancellationToken(); + switch (e.HttpClient.Request.Method.ToUpperInvariant()) + { + case "GET": + var body =await IHttpService.Instance.GetAsync(url); + e.Ok(body??"500", new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*"), new HttpHeader("Access-Control-Allow-Headers", "*") }); + return; + case "POST": + var requestStream = new StreamWriter(new MemoryStream()); + requestStream.Write(e.HttpClient.Request.BodyString); + var send = new HttpRequestMessage { + Method= HttpMethod.Post, + Content= new StreamContent(requestStream.BaseStream), + }; + send.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(e.HttpClient.Request.ContentType); + send.Content.Headers.ContentLength = e.HttpClient.Request.BodyString.Length; + var conext = await IHttpService.Instance.SendAsync(url, send,null,false,new CancellationToken()); + e.Ok(conext ?? "500", new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*"), new HttpHeader("Access-Control-Allow-Headers", "*") }); + return; + } + //e.Ok(respone, new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*") }); + } public async Task OnRequest(object sender, SessionEventArgs e) { #if DEBUG @@ -73,8 +99,21 @@ namespace System.Application.Services.Implementation } if (e.HttpClient.Request.Host == "local.steampp.net") { - e.Ok(Scripts.FirstOrDefault(x => x.JsPathUrl == e.HttpClient.Request.RequestUri.LocalPath)?.Content ?? "404", JsHeader); - return; + if (e.HttpClient.Request.Method.ToUpperInvariant() == "OPTIONS") { + e.Ok("", new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*"),new HttpHeader("Access-Control-Allow-Headers", "*") }); + return; + } + var type = e.HttpClient.Request.Headers.GetFirstHeader("requestType")?.Value; + switch (type) + { + case "xhr": + await HttpRequest(e); + + return; + default: + e.Ok(Scripts.FirstOrDefault(x => x.JsPathUrl == e.HttpClient.Request.RequestUri.LocalPath)?.Content ?? "404", JsHeader); + return; + } } foreach (var item in ProxyDomains) { diff --git a/src/ST.Client/Services/Implementation/ScriptManagerServiceImpl.cs b/src/ST.Client/Services/Implementation/ScriptManagerServiceImpl.cs index c29069d90..bb1f9e73c 100644 --- a/src/ST.Client/Services/Implementation/ScriptManagerServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/ScriptManagerServiceImpl.cs @@ -91,6 +91,7 @@ namespace System.Application.Services.Implementation info.Id = pid.Value; var cachePath = Path.Combine(IOPath.CacheDirectory, url); info.FilePath = url; + info.IsBuild = build; info.CachePath = url; if (await BuildScriptAsync(info, build)) {