Added Server Sent Events

This commit is contained in:
Michael Nolan
2022-09-01 00:26:26 -05:00
parent 3162360069
commit 9277fda0d5
4 changed files with 440 additions and 20 deletions
+48 -1
View File
@@ -79,6 +79,53 @@ internal class SizedStream : Stream
/// Method (ex GET, POST, HEAD)
/// </summary>
public string Method { get; set; }
Func<bool> isConnected;
public bool Connected {
get{
if(isConnected != null)
{
return isConnected();
}
return true;
}
}
public ServerContext(string method,Stream strm,string path,Dictionary<string,List<string>> headers,Func<bool> isConnected)
{
Method = method;
NetworkStream = strm;
RequestHeaders = headers;
ResponseHeaders = new Dictionary<string, List<string>>();
QueryParams = new Dictionary<string, List<string>>();
ResponseHeaders.Add("Server","Tesses.WebServer");
ResponseHeaders.Add("Connection","close");
RawUrl=path;
StatusCode = 200;
// /joel/path/luigi?local=jim&john_surname=connor&demi_surname=lovato&local=tim
string[] splitUrl = path.Split(new char[] { '?' }, 2);
if (splitUrl.Length > 0)
{
UrlPath = splitUrl[0];
OriginalUrlPath=splitUrl[0];
if (splitUrl.Length == 2)
{
//local=jim&john_surname=connor&demi_surname=lovato&local=tim
//we want to split on &
q_parm = splitUrl[1];
}
else
{
q_parm = "";
}
ResetQueryParms();
}
this.isConnected=isConnected;
}
public ServerContext(string method,Stream strm,string path,Dictionary<string,List<string>> headers)
{
Method = method;
@@ -111,7 +158,7 @@ internal class SizedStream : Stream
}
ResetQueryParms();
}
isConnected=null;
}
/// <summary>
/// Reset query parms (If api sets them)