123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.IO;
- using System.Net;
- namespace NetCoreServer
- {
-
-
-
-
- public class HttpsServer : SslServer
- {
-
-
-
-
-
-
- public HttpsServer(SslContext context, IPAddress address, int port) : base(context, address, port) { Cache = new FileCache(); }
-
-
-
-
-
-
- public HttpsServer(SslContext context, string address, int port) : base(context, address, port) { Cache = new FileCache(); }
-
-
-
-
-
- public HttpsServer(SslContext context, DnsEndPoint endpoint) : base(context, endpoint) { Cache = new FileCache(); }
-
-
-
-
-
- public HttpsServer(SslContext context, IPEndPoint endpoint) : base(context, endpoint) { Cache = new FileCache(); }
-
-
-
- public FileCache Cache { get; }
-
-
-
-
-
-
-
- public void AddStaticContent(string path, string prefix = "/", string filter = "*.*", TimeSpan? timeout = null)
- {
- timeout ??= TimeSpan.FromHours(1);
- bool Handler(FileCache cache, string key, byte[] value, TimeSpan timespan)
- {
- var response = new HttpResponse();
- response.SetBegin(200);
- response.SetContentType(Path.GetExtension(key));
- response.SetHeader("Cache-Control", $"max-age={timespan.Seconds}");
- response.SetBody(value);
- return cache.Add(key, response.Cache.Data, timespan);
- }
- Cache.InsertPath(path, prefix, filter, timeout.Value, Handler);
- }
-
-
-
-
- public void RemoveStaticContent(string path) { Cache.RemovePath(path); }
-
-
-
- public void ClearStaticContent() { Cache.Clear(); }
- protected override SslSession CreateSession() { return new HttpsSession(this); }
- #region IDisposable implementation
-
- private bool _disposed;
- protected override void Dispose(bool disposingManagedResources)
- {
- if (!_disposed)
- {
- if (disposingManagedResources)
- {
-
- Cache.Dispose();
- }
-
-
-
- _disposed = true;
- }
-
- base.Dispose(disposingManagedResources);
- }
-
-
-
- #endregion
- }
- }
|