This commit is contained in:
2026-06-15 18:18:16 +08:00
parent 97c9fba14e
commit 2b9f134e5f
4164 changed files with 386922 additions and 79 deletions

View File

@@ -0,0 +1,59 @@
using System;
using System.IO;
namespace Best.HTTP.Hosts.Connections
{
public enum SupportedProtocols
{
Unknown,
HTTP,
WebSocket,
ServerSentEvents
}
public static class HTTPProtocolFactory
{
public const string W3C_HTTP1 = "http/1.1";
#if (!UNITY_WEBGL || UNITY_EDITOR) && !BESTHTTP_DISABLE_ALTERNATE_SSL
public const string W3C_HTTP2 = "h2";
#endif
public static SupportedProtocols GetProtocolFromUri(Uri uri)
{
if (uri == null || uri.Scheme == null)
throw new Exception("Malformed URI in GetProtocolFromUri");
string scheme = uri.Scheme.ToLowerInvariant();
switch (scheme)
{
case "ws":
case "wss":
return SupportedProtocols.WebSocket;
default:
return SupportedProtocols.HTTP;
}
}
public static bool IsSecureProtocol(Uri uri)
{
if (uri == null || uri.Scheme == null)
throw new Exception("Malformed URI in IsSecureProtocol");
string scheme = uri.Scheme.ToLowerInvariant();
switch (scheme)
{
// http
case "https":
// WebSocket
case "wss":
return true;
}
return false;
}
}
}