-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change HTTPS proxy to work off redirects towards an external proxy (#668
) This allows us to use an external proxy, instead of the buggy proxy that I had originally written. Sadly we cant redirect directly to prod because of a bug in the original game (after a redirect it still uses the pre-redirect host header value with the new server). In practice, the proxy.json config will probably just point to the same machine as Refresh.HttpsProxy itself, but with a different port, which is hosting a standard nginx HTTP proxy server. This PR also fixes the middleware order
- Loading branch information
Showing
7 changed files
with
75 additions
and
92 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Refresh.Common/Extensions/NameValueCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections.Specialized; | ||
using System.Text; | ||
using System.Web; | ||
|
||
namespace Refresh.Common.Extensions; | ||
|
||
public static class NameValueCollectionExtensions | ||
{ | ||
public static string ToQueryString(this NameValueCollection queryParams) | ||
{ | ||
StringBuilder builder = new(); | ||
|
||
if (queryParams.Count == 0) | ||
return string.Empty; | ||
|
||
builder.Append('?'); | ||
for (int i = 0; i < queryParams.Count; i++) | ||
{ | ||
string? key = queryParams.GetKey(i); | ||
string? val = queryParams.Get(i); | ||
|
||
if (key == null) | ||
continue; | ||
|
||
builder.Append(HttpUtility.UrlEncode(key)); | ||
builder.Append('='); | ||
if(val != null) | ||
builder.Append(HttpUtility.UrlEncode(val)); | ||
|
||
if(i < queryParams.Count - 1) | ||
builder.Append('&'); | ||
} | ||
|
||
return builder.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Net; | ||
using Bunkum.Core.Database; | ||
using Bunkum.Core.Endpoints.Middlewares; | ||
using Bunkum.Listener.Request; | ||
using Refresh.Common.Extensions; | ||
using Refresh.HttpsProxy.Config; | ||
|
||
namespace Refresh.HttpsProxy.Middlewares; | ||
|
||
public class RedirectMiddleware(ProxyConfig config) : IMiddleware | ||
{ | ||
public void HandleRequest(ListenerContext context, Lazy<IDatabaseContext> database, Action next) | ||
{ | ||
UriBuilder uri = new(config.TargetServerUrl) | ||
{ | ||
Path = context.Uri.AbsolutePath, | ||
}; | ||
|
||
context.Query["force_ps3_digest"] = config.Ps3DigestIndex.ToString(); | ||
context.Query["force_ps4_digest"] = config.Ps4DigestIndex.ToString(); | ||
|
||
uri.Query = context.Query.ToQueryString(); | ||
|
||
context.ResponseCode = HttpStatusCode.TemporaryRedirect; | ||
context.ResponseHeaders["Location"] = uri.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters