Doing some fixup
This commit is contained in:
@@ -5,9 +5,11 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using HeyRed.Mime;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tesses.WebServer
|
||||
{
|
||||
@@ -200,8 +202,7 @@ namespace Tesses.WebServer
|
||||
|
||||
}
|
||||
ctx.ResponseHeaders.Add("Content-Length", (end - start + 1).ToString());
|
||||
ctx.ResponseHeaders.Add("Content-Type", contentType);
|
||||
|
||||
ctx.WithMimeType(contentType);
|
||||
await ctx.WriteHeadersAsync();
|
||||
if (!ctx.Method.Equals("HEAD", StringComparison.Ordinal))
|
||||
{
|
||||
@@ -537,6 +538,11 @@ namespace Tesses.WebServer
|
||||
}
|
||||
return files;
|
||||
}
|
||||
public static HttpFileResponse ParseBodyWithTempDirectory(this ServerContext request)
|
||||
{
|
||||
DateTime dt=DateTime.Now;
|
||||
return request.ParseBodyWithTempDirectory(Path.Combine(Path.GetTempPath(),$"TWSUPLOAD_{dt.ToString("yyyyMMdd_HHmmss")}_{ServerContext.UniqueNumber()}"));
|
||||
}
|
||||
/// <summary>
|
||||
/// Parses body of the request including form and multi-part form data, allowing multiple file with same key and storing the files in a temp directory specified by the user.
|
||||
/// </summary>
|
||||
@@ -568,6 +574,7 @@ namespace Tesses.WebServer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public sealed class HttpFileResponseEntry
|
||||
{
|
||||
public HttpFileResponseEntry(string path, string filename, string fieldname, string contype)
|
||||
@@ -584,8 +591,10 @@ namespace Tesses.WebServer
|
||||
public string Path {get;}
|
||||
|
||||
public string FieldName {get;}
|
||||
|
||||
[JsonIgnore]
|
||||
public FileInfo FileInfo => new FileInfo(Path);
|
||||
[JsonIgnore]
|
||||
public object PrivateData {get;set;}=null;
|
||||
|
||||
public Stream OpenRead()
|
||||
{
|
||||
@@ -606,9 +615,15 @@ namespace Tesses.WebServer
|
||||
public IReadOnlyList<HttpFileResponseEntry> Files {get;}
|
||||
public string Directory {get;}
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
System.IO.Directory.Delete(Directory,true);
|
||||
if(System.IO.Directory.Exists(Directory))
|
||||
System.IO.Directory.Delete(Directory,true);
|
||||
}
|
||||
~HttpFileResponse()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user