some testing for get web gui requests
This commit is contained in:
parent
cf73689e02
commit
95729fdaba
1 changed files with 74 additions and 44 deletions
|
|
@ -96,7 +96,7 @@ namespace BetterSecondBot.HttpServer
|
|||
webui myUI = new webui(Config,Bot);
|
||||
while (Bot.KillMe == false)
|
||||
{
|
||||
HttpListenerContext ctx = await listener.GetContextAsync();
|
||||
HttpListenerContext ctx = await listener.GetContextAsync().ConfigureAwait(true);
|
||||
HttpListenerRequest req = ctx.Request;
|
||||
HttpListenerResponse resp = ctx.Response;
|
||||
string test = req.Url.AbsolutePath.Substring(1);
|
||||
|
|
@ -110,13 +110,24 @@ namespace BetterSecondBot.HttpServer
|
|||
resp.ContentType = "text/html";
|
||||
if (req.HttpMethod == "GET")
|
||||
{
|
||||
KeyValuePair<string, byte[]> replydata = myUI.process(http_args, req.Cookies);
|
||||
KeyValuePair<string, byte[]> replydata = myUI.Get_Process(http_args, req.Cookies);
|
||||
if (replydata.Value != null)
|
||||
{
|
||||
resp.ContentType = replydata.Key;
|
||||
data = replydata.Value;
|
||||
resp.ContentLength64 = data.LongLength;
|
||||
await resp.OutputStream.WriteAsync(data, 0, data.Length);
|
||||
await resp.OutputStream.WriteAsync(data, 0, data.Length).ConfigureAwait(true);
|
||||
resp.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
data = Encoding.UTF8.GetBytes("error with service");
|
||||
resp.ContentLength64 = data.LongLength;
|
||||
resp.ContentType = "text/html";
|
||||
await resp.OutputStream.WriteAsync(data, 0, data.Length).ConfigureAwait(true);
|
||||
resp.Close();
|
||||
}
|
||||
}
|
||||
else if (req.HttpMethod == "POST")
|
||||
{
|
||||
string text;
|
||||
|
|
@ -136,13 +147,23 @@ namespace BetterSecondBot.HttpServer
|
|||
}
|
||||
}
|
||||
|
||||
resp.StatusCode = 200;
|
||||
KeyValuePair<bool, string> UI_process = myUI.Post_process(http_args,post_args);
|
||||
if (UI_process.Key == false)
|
||||
{
|
||||
data = Encoding.UTF8.GetBytes(UI_process.Value);
|
||||
resp.ContentLength64 = data.LongLength;
|
||||
await resp.OutputStream.WriteAsync(data, 0, data.Length).ConfigureAwait(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool accept_request = false;
|
||||
string why_request_failed = "Bad signing request";
|
||||
|
||||
string command = "";
|
||||
string arg = "";
|
||||
string signing_code;
|
||||
resp.StatusCode = 200;
|
||||
|
||||
if (post_args.ContainsKey("command") == true)
|
||||
{
|
||||
command = post_args["command"];
|
||||
|
|
@ -180,6 +201,8 @@ namespace BetterSecondBot.HttpServer
|
|||
}
|
||||
resp.ContentLength64 = data.LongLength;
|
||||
await resp.OutputStream.WriteAsync(data, 0, data.Length);
|
||||
}
|
||||
|
||||
resp.Close();
|
||||
}
|
||||
}
|
||||
|
|
@ -203,11 +226,18 @@ namespace BetterSecondBot.HttpServer
|
|||
ConsoleLog.Crit("if running on windows please check: https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-http-and-https?redirectedfrom=MSDN");
|
||||
}
|
||||
if (ok == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConsoleLog.Status("Listening for connections on " + url + "");
|
||||
Task listenTask = HandleIncomingConnections();
|
||||
listenTask.GetAwaiter().GetResult();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
ConsoleLog.Status("Http interface killed itself: "+e.ToString()+"");
|
||||
}
|
||||
}
|
||||
listener.Close();
|
||||
})
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue