[1.1.9] Modify Output of SendFileResponse

This commit is contained in:
BlubbFish 2019-04-21 15:01:14 +02:00
parent 9705663328
commit cf3413a3d7
2 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden
@ -10,7 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("BlubbFish")] [assembly: AssemblyCompany("BlubbFish")]
[assembly: AssemblyProduct("Bot-Utils")] [assembly: AssemblyProduct("Bot-Utils")]
[assembly: AssemblyCopyright("Copyright © 2018 - 15.04.2019")] [assembly: AssemblyCopyright("Copyright © 2018 - 21.04.2019")]
[assembly: AssemblyTrademark("© BlubbFish")] [assembly: AssemblyTrademark("© BlubbFish")]
[assembly: AssemblyCulture("")] [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, // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben: // indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.8")] [assembly: AssemblyVersion("1.1.9")]
[assembly: AssemblyFileVersion("1.1.8")] [assembly: AssemblyFileVersion("1.1.9")]
/* /*
* 1.1.0 Remove Helper from Bot-Utils * 1.1.0 Remove Helper from Bot-Utils
@ -46,4 +45,5 @@ using System.Runtime.InteropServices;
* also put returntype boolean, add function that parse post params, if path is a dictionary try to load index.html * 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.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.8 Add logger to Webserver Class
* 1.1.9 Modify Output of SendFileResponse
*/ */

View File

@ -46,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; String restr = cont.Request.Url.PathAndQuery;
if(restr.StartsWith("/")) { if(restr.StartsWith("/")) {
if(restr.IndexOf("?") != -1) { if(restr.IndexOf("?") != -1) {
@ -71,6 +71,9 @@ namespace BlubbFish.Utils.IoT.Bots {
break; break;
} }
cont.Response.OutputStream.Write(output, 0, output.Length); cont.Response.OutputStream.Write(output, 0, output.Length);
if(printOutput) {
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
}
return true; return true;
} else { } else {
String file = File.ReadAllText(folder + "/" + restr); String file = File.ReadAllText(folder + "/" + restr);
@ -89,7 +92,9 @@ namespace BlubbFish.Utils.IoT.Bots {
break; break;
} }
cont.Response.OutputStream.Write(buf, 0, buf.Length); cont.Response.OutputStream.Write(buf, 0, buf.Length);
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery); if(printOutput) {
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
}
return true; return true;
} }
} catch(Exception e) { } catch(Exception e) {
@ -99,7 +104,9 @@ namespace BlubbFish.Utils.IoT.Bots {
} }
} }
} }
Helper.WriteError("404 - " + cont.Request.Url.PathAndQuery + " not found!"); if(printOutput) {
Helper.WriteError("404 - " + cont.Request.Url.PathAndQuery + " not found!");
}
cont.Response.StatusCode = 404; cont.Response.StatusCode = 404;
return false; return false;
} }