26 lines
627 B
26 lines
627 B
#if !NET20
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Apewer.WebSocket
|
|
{
|
|
internal static class SubProtocolNegotiator
|
|
{
|
|
public static string Negotiate(IEnumerable<string> server, IEnumerable<string> client)
|
|
{
|
|
if (!server.Any() || !client.Any()) {
|
|
return null;
|
|
}
|
|
|
|
var matches = client.Intersect(server);
|
|
if (!matches.Any()) {
|
|
throw new SubProtocolNegotiationFailureException("Unable to negotiate a subprotocol");
|
|
}
|
|
return matches.First();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|