[Modify] Add it

This commit is contained in:
sta 2020-12-06 21:45:02 +09:00
parent 688cb155c4
commit 26479fca1a

View File

@ -39,6 +39,7 @@
using System;
using System.Security.Principal;
using System.Text;
using WebSocketSharp.Net.WebSockets;
namespace WebSocketSharp.Net
@ -200,6 +201,34 @@ namespace WebSocketSharp.Net
return _listener.RegisterContext (this);
}
internal void SendError ()
{
try {
_response.StatusCode = _errorStatus;
_response.ContentType = "text/html";
var content = new StringBuilder (64);
content.AppendFormat (
"<html><body><h1>{0} {1}", _errorStatus, _response.StatusDescription
);
if (_error != null && _error.Length > 0)
content.AppendFormat (" ({0})</h1></body></html>", _error);
else
content.Append ("</h1></body></html>");
var enc = Encoding.UTF8;
var entity = enc.GetBytes (content.ToString ());
_response.ContentEncoding = enc;
_response.ContentLength64 = entity.LongLength;
_response.Close (entity, true);
}
catch {
_connection.Close (true);
}
}
internal void Unregister ()
{
_listener.UnregisterContext (this);