chatr/ChatrServer/Chatr/AppConfig.cs

74 lines
1.9 KiB
C#

using Tesses.WebServer;
namespace Tesses.Chatr.Server
{
public class AppConfig
{
internal AppConfig(ServerContext ctx,Arguments args)
{
bool hasWSPort=false;
string ws_port_str;
ushort ws_port;
if(ctx.RequestHeaders.TryGetFirst("WS-Port",out ws_port_str))
{
if(ushort.TryParse(ws_port_str,out ws_port))
{
hasWSPort=true;
WSPort=ws_port;
}
}
if(!hasWSPort)
{
if(args.TryGetValueNotNull("ws-port",out ws_port_str))
{
if(ushort.TryParse(ws_port_str,out ws_port))
{
hasWSPort=true;
WSPort=ws_port;
}
}else{
WSPort=4030;
}
}
hasWSPort=false; //reusing bool to save ram
if(ctx.RequestHeaders.TryGetFirst("WS-Secure",out ws_port_str)) //reusing string to save ram
{
if(ws_port_str=="true") {
hasWSPort=true;
WSS=true;
}
}
if(!hasWSPort)
{
if(args.TryGetValue("ws-secure",out ws_port_str))
{
if(string.IsNullOrWhiteSpace(ws_port_str))
{
WSS=true;
}else{
WSS = ws_port_str=="true";
}
}else{
WSS=false;
}
}
if(ctx.QueryParams.TryGetFirst("Chatr-Session",out ws_port_str))
{
SessionId=ws_port_str;
}
}
public string SessionId {get;set;}
public ushort WSPort {get;set;}
public bool WSS {get;set;}
public bool WS_SAME_AS_HTTP {get{return WebSocketSameAsHttp;}set {WebSocketSameAsHttp=value;}}
public static bool WebSocketSameAsHttp {get;set;}
}
}