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.

26 lines
627 B

  1. #if !NET20
  2. using System;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. namespace Apewer.WebSocket
  6. {
  7. internal static class SubProtocolNegotiator
  8. {
  9. public static string Negotiate(IEnumerable<string> server, IEnumerable<string> client)
  10. {
  11. if (!server.Any() || !client.Any()) {
  12. return null;
  13. }
  14. var matches = client.Intersect(server);
  15. if (!matches.Any()) {
  16. throw new SubProtocolNegotiationFailureException("Unable to negotiate a subprotocol");
  17. }
  18. return matches.First();
  19. }
  20. }
  21. }
  22. #endif