From e93a82b6e8fd6367908f2bb881fe16e3662b6d7e Mon Sep 17 00:00:00 2001 From: Madpeter Date: Sun, 3 May 2020 23:45:16 +0100 Subject: [PATCH] adjusts http get interface to not accept args on get commands and to clean up the uri --- CLI/HttpServer/http_server.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/CLI/HttpServer/http_server.cs b/CLI/HttpServer/http_server.cs index bd13e1b..d8d4971 100644 --- a/CLI/HttpServer/http_server.cs +++ b/CLI/HttpServer/http_server.cs @@ -7,6 +7,7 @@ using BSB.bottypes; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using System.Text; using System.Threading; @@ -100,26 +101,19 @@ namespace BetterSecondBot.HttpServer HttpListenerRequest req = ctx.Request; HttpListenerResponse resp = ctx.Response; string test = req.Url.AbsolutePath.Substring(1); - string[] http_args = test.Split('/', StringSplitOptions.RemoveEmptyEntries); + test = test.Replace(Config.HttpPublicUrlBase, ""); + List http_args = test.Split('/', StringSplitOptions.RemoveEmptyEntries).ToList(); byte[] data = Encoding.UTF8.GetBytes("totaly fucked"); resp.StatusCode = 404; if (req.HttpMethod == "GET") { resp.StatusCode = 200; string command = "status"; - string arg = ""; - if (helpers.notempty(http_args) == true) + if (http_args.Count > 0) { - if (http_args.Length >= 1) - { - command = http_args[0]; - } - if (http_args.Length == 2) - { - arg = http_args[1]; - } + command = http_args.Last(); } - string content = String.Join("{@}", get_controler.Call(command, arg)); + string content = String.Join("{@}", get_controler.Call(command, "")); data = Encoding.UTF8.GetBytes(content); } else if (req.HttpMethod == "POST")