You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
48 lines
1.5 KiB
#if !NET20
|
|
|
|
using System;
|
|
|
|
namespace Apewer.WebSocket
|
|
{
|
|
internal class HandlerFactory
|
|
{
|
|
public static ComposableHandler BuildHandler(HttpRequest request, Action<string> onMessage, Action onClose, Action<byte[]> onBytes, Action<byte[]> onPing, Action<byte[]> onPong)
|
|
{
|
|
var version = GetVersion(request);
|
|
|
|
switch (version)
|
|
{
|
|
case "76":
|
|
return Draft76Handler.Create(request, onMessage);
|
|
case "7":
|
|
case "8":
|
|
case "13":
|
|
return Hybi13Handler.Create(request, onMessage, onClose, onBytes, onPing, onPong);
|
|
case "policy-file-request":
|
|
return FlashSocketPolicyRequestHandler.Create(request);
|
|
}
|
|
|
|
throw new WebSocketException(StatusCodes.UnsupportedDataType);
|
|
}
|
|
|
|
public static string GetVersion(HttpRequest request)
|
|
{
|
|
string version;
|
|
if (request.Headers.TryGetValue("Sec-WebSocket-Version", out version))
|
|
return version;
|
|
|
|
if (request.Headers.TryGetValue("Sec-WebSocket-Draft", out version))
|
|
return version;
|
|
|
|
if (request.Headers.ContainsKey("Sec-WebSocket-Key1"))
|
|
return "76";
|
|
|
|
if ((request.Body != null) && request.Body.ToLower().Contains("policy-file-request"))
|
|
return "policy-file-request";
|
|
|
|
return "75";
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|