feat(SimpleWebTransport): adding option to set server and client port different (#3477)

* feat(SimpleWebTransport): adding option to set server and client port different

When running websocket server behind reverse proxy client should connect via port 80 or 443. the reverse proxy should then forward requests to the ServerPort  running on localhost.

* Update Assets/Mirror/Transports/SimpleWeb/SimpleWebTransport.cs

---------

Co-authored-by: mischa <16416509+vis2k@users.noreply.github.com>
This commit is contained in:
James Frowen 2023-05-04 03:59:47 +01:00 committed by GitHub
parent 0f41aa7a3e
commit f200b907ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,9 @@ public class SimpleWebTransport : Transport, PortTransport
public ushort port = 7778; public ushort port = 7778;
public ushort Port { get => port; set => port=value; } public ushort Port { get => port; set => port=value; }
[Tooltip("Tells the client to use the default port. This is useful when connecting to reverse proxy rather than directly to websocket server")]
public bool ClientUseDefaultPort = 7778;
[Tooltip("Protect against allocation attacks by keeping the max message size small. Otherwise an attacker might send multiple fake packets with 2GB headers, causing the server to run out of memory after allocating multiple large packets.")] [Tooltip("Protect against allocation attacks by keeping the max message size small. Otherwise an attacker might send multiple fake packets with 2GB headers, causing the server to run out of memory after allocating multiple large packets.")]
public int maxMessageSize = 16 * 1024; public int maxMessageSize = 16 * 1024;
@ -122,8 +125,10 @@ public override void ClientConnect(string hostname)
{ {
Scheme = GetClientScheme(), Scheme = GetClientScheme(),
Host = hostname, Host = hostname,
Port = port
}; };
// https://github.com/MirrorNetworking/Mirror/pull/3477
if (!ClientUseDefaultPort)
builder.Port = Port;
ClientConnect(builder.Uri); ClientConnect(builder.Uri);
} }