Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf3413a3d7 | ||
|
|
9705663328 | ||
|
|
6840fced1c | ||
|
|
39eac5222c |
@@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
@@ -10,7 +9,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("Bot-Utils")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018 - 12.03.2019")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018 - 21.04.2019")]
|
||||
[assembly: AssemblyTrademark("© BlubbFish")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@@ -32,8 +31,8 @@ using System.Runtime.InteropServices;
|
||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
// indem Sie "*" wie unten gezeigt eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: AssemblyVersion("1.1.9")]
|
||||
[assembly: AssemblyFileVersion("1.1.9")]
|
||||
|
||||
/*
|
||||
* 1.1.0 Remove Helper from Bot-Utils
|
||||
@@ -42,5 +41,9 @@ using System.Runtime.InteropServices;
|
||||
* 1.1.3 Variables parsing now as a String
|
||||
* 1.1.4 add Woff as Binary type
|
||||
* 1.1.5 add a function to send an object as json directly
|
||||
* 1.1.6 rename functions and make SendFileResponse with a parameter for the folder,
|
||||
* 1.1.6 rename functions and make SendFileResponse with a parameter for the folder (default resources),
|
||||
* also put returntype boolean, add function that parse post params, if path is a dictionary try to load index.html
|
||||
* 1.1.7 Restrucutre loading, so that all is init and after the listener is started, REQUEST_URL_HOST gives now host and port
|
||||
* 1.1.8 Add logger to Webserver Class
|
||||
* 1.1.9 Modify Output of SendFileResponse
|
||||
*/
|
||||
|
||||
+16
-3
@@ -15,11 +15,17 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
protected Dictionary<String, String> config;
|
||||
protected static InIReader requests;
|
||||
protected HttpListener httplistener;
|
||||
protected ABackend databackend;
|
||||
protected ProgramLogger logger = new ProgramLogger();
|
||||
|
||||
public Webserver(ABackend backend, Dictionary<String, String> settings, InIReader requestslookup) {
|
||||
this.config = settings;
|
||||
requests = requestslookup;
|
||||
backend.MessageIncomming += this.Backend_MessageIncomming;
|
||||
this.databackend = backend;
|
||||
}
|
||||
|
||||
protected void StartListen() {
|
||||
this.databackend.MessageIncomming += this.Backend_MessageIncomming;
|
||||
this.httplistener = new HttpListener();
|
||||
this.httplistener.Prefixes.Add(this.config["prefix"]);
|
||||
this.httplistener.Start();
|
||||
@@ -40,7 +46,7 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
});
|
||||
}
|
||||
|
||||
public static Boolean SendFileResponse(HttpListenerContext cont, String folder = "resources") {
|
||||
public static Boolean SendFileResponse(HttpListenerContext cont, String folder = "resources", Boolean printOutput = true) {
|
||||
String restr = cont.Request.Url.PathAndQuery;
|
||||
if(restr.StartsWith("/")) {
|
||||
if(restr.IndexOf("?") != -1) {
|
||||
@@ -65,6 +71,9 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
break;
|
||||
}
|
||||
cont.Response.OutputStream.Write(output, 0, output.Length);
|
||||
if(printOutput) {
|
||||
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
String file = File.ReadAllText(folder + "/" + restr);
|
||||
@@ -74,7 +83,7 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
file = file.Replace("\"{%" + item.Key.ToUpper() + "%}\"", item.Value);
|
||||
}
|
||||
}
|
||||
file = file.Replace("{%REQUEST_URL_HOST%}", cont.Request.Url.Host);
|
||||
file = file.Replace("{%REQUEST_URL_HOST%}", cont.Request.Url.Host+":"+cont.Request.Url.Port);
|
||||
Byte[] buf = Encoding.UTF8.GetBytes(file);
|
||||
cont.Response.ContentLength64 = buf.Length;
|
||||
switch(end) {
|
||||
@@ -83,7 +92,9 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
break;
|
||||
}
|
||||
cont.Response.OutputStream.Write(buf, 0, buf.Length);
|
||||
if(printOutput) {
|
||||
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} catch(Exception e) {
|
||||
@@ -93,7 +104,9 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(printOutput) {
|
||||
Helper.WriteError("404 - " + cont.Request.Url.PathAndQuery + " not found!");
|
||||
}
|
||||
cont.Response.StatusCode = 404;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user