diff --git a/nanoFramework.WebServer/Authentication.cs b/nanoFramework.WebServer/Authentication.cs
index 952bd93..c237fb8 100644
--- a/nanoFramework.WebServer/Authentication.cs
+++ b/nanoFramework.WebServer/Authentication.cs
@@ -10,7 +10,7 @@
namespace nanoFramework.WebServer
{
///
- /// The authentication to be used by the server
+ /// The authentication to be used by the server.
///
public class Authentication
{
@@ -20,7 +20,7 @@ public class Authentication
public AuthenticationType AuthenticationType { get; internal set; }
///
- /// The network credential user and password
+ /// The network credential user and password.
///
public NetworkCredential Credentials { get; internal set; } = null;
@@ -29,18 +29,29 @@ public class Authentication
///
public string ApiKey { get; internal set; } = null;
+ ///
+ /// Creates an autentication class from a credential.
+ ///
+ /// The credentials.
public Authentication(NetworkCredential credential)
{
AuthenticationType = AuthenticationType.Basic;
Credentials = credential;
}
+ ///
+ /// Creates an authentication from a key.
+ ///
+ /// The key.
public Authentication(string apiKey)
{
AuthenticationType = AuthenticationType.ApiKey;
ApiKey = apiKey;
}
+ ///
+ /// Creates an empty authenticate.
+ ///
public Authentication()
{
AuthenticationType = AuthenticationType.None;
diff --git a/nanoFramework.WebServer/MethodAttribute.cs b/nanoFramework.WebServer/MethodAttribute.cs
index 5f489d4..7b3e8fe 100644
--- a/nanoFramework.WebServer/MethodAttribute.cs
+++ b/nanoFramework.WebServer/MethodAttribute.cs
@@ -8,13 +8,20 @@
namespace nanoFramework.WebServer
{
///
- /// The HTTP Method
+ /// The HTTP Method.
///
[AttributeUsage(AttributeTargets.Method)]
public class MethodAttribute : Attribute
{
+ ///
+ /// Gets or sets the method.
+ ///
public string Method { get; set; }
+ ///
+ /// Creates a method attribute.
+ ///
+ /// The method.
public MethodAttribute(string method)
{
Method = method;
diff --git a/nanoFramework.WebServer/RouteAttribute.cs b/nanoFramework.WebServer/RouteAttribute.cs
index d1bdf6e..bc6f979 100644
--- a/nanoFramework.WebServer/RouteAttribute.cs
+++ b/nanoFramework.WebServer/RouteAttribute.cs
@@ -8,17 +8,20 @@
namespace nanoFramework.WebServer
{
///
- /// Route custom attribute
+ /// Route custom attribute.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class RouteAttribute : Attribute
{
+ ///
+ /// Gets or sets the route.
+ ///
public string Route { get; set; }
///
- /// A route attribute
+ /// A route attribute.
///
- /// The route like route/second/third
+ /// The complete route like 'route/second/third'.
public RouteAttribute(string route)
{
Route = route;
diff --git a/nanoFramework.WebServer/WebServer.cs b/nanoFramework.WebServer/WebServer.cs
index 924450e..1cba312 100644
--- a/nanoFramework.WebServer/WebServer.cs
+++ b/nanoFramework.WebServer/WebServer.cs
@@ -465,10 +465,11 @@ public static void SendFileOverHTTP(HttpListenerResponse response, StorageFile s
/// to send the content over.
/// Name of the file to send over .
/// Content of the file to send.
- /// /// The type of file, if empty string, then will use auto detection
+ /// The type of file, if empty string, then will use auto detection.
public static void SendFileOverHTTP(HttpListenerResponse response, string fileName, byte[] content, string contentType = "")
{
- contentType = contentType == "" ? GetContentTypeFromFileName(fileName.Substring(fileName.LastIndexOf('.'))) : contentType;
+ // If no extension, we will get the full file name
+ contentType = contentType == "" ? GetContentTypeFromFileName(fileName.Substring(fileName.LastIndexOf('.') + 1)) : contentType;
response.ContentType = contentType;
response.ContentLength64 = content.Length;
@@ -483,8 +484,6 @@ public static void SendFileOverHTTP(HttpListenerResponse response, string fileNa
// Writes data to output stream
response.OutputStream.Write(content, (int)bytesSent, (int)bytesToSend);
- // allow some time to physically send the bits. Can be reduce to 10 or even less if not too much other code running in parallel
-
// update bytes sent
bytesSent += bytesToSend;
}
@@ -676,49 +675,58 @@ private void ListInterfaces()
///
/// Get the MIME-type for a file name.
///
- /// File name to get content type for.
+ /// File extension to get content type for.
/// The MIME-type for the file name.
- private static string GetContentTypeFromFileName(string fileName)
+ private static string GetContentTypeFromFileName(string fileExt)
{
// normalize to lower case to speed comparison
- fileName = fileName.ToLower();
+ fileExt = fileExt.ToLower();
string contentType = "text/html";
//determine the type of file for the http header
- if (fileName == ".cs" ||
- fileName == ".txt" ||
- fileName == ".csproj"
- )
+ if (fileExt == "cs" ||
+ fileExt == "txt" ||
+ fileExt == "csproj")
{
contentType = "text/plain";
}
- else if (fileName == ".jpg" ||
- fileName == ".bmp" ||
- fileName == ".jpeg" ||
- fileName == ".png"
- )
+ else if (fileExt == "jpg" ||
+ fileExt == "jpeg" ||
+ fileExt == "jpe")
+ {
+ contentType = "image/jpeg";
+ }
+ else if (fileExt == "bmp" ||
+ fileExt == "png" ||
+ fileExt == "gif" ||
+ fileExt == "ief")
{
- contentType = "image";
+ contentType = $"image/{fileExt}";
}
- else if (fileName == ".htm" ||
- fileName == ".html"
- )
+ else if (fileExt == "htm" ||
+ fileExt == "html")
{
contentType = "text/html";
}
- else if (fileName == ".mp3")
+ else if (fileExt == "mp3")
{
contentType = "audio/mpeg";
}
- else if (fileName == ".css")
+ else if (fileExt == "css")
{
contentType = "text/css";
}
- else if (fileName == ".ico")
+ else if (fileExt == "ico")
{
contentType = "image/x-icon";
}
+ else if (fileExt == "zip" ||
+ fileExt == "json" ||
+ fileExt == "pdf")
+ {
+ contentType = $"application/{fileExt}";
+ }
return contentType;
}
diff --git a/nanoFramework.WebServer/nanoFramework.WebServer.nfproj b/nanoFramework.WebServer/nanoFramework.WebServer.nfproj
index 44aee1e..ade4377 100644
--- a/nanoFramework.WebServer/nanoFramework.WebServer.nfproj
+++ b/nanoFramework.WebServer/nanoFramework.WebServer.nfproj
@@ -91,6 +91,9 @@
+
+
+