Request.cs 986 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Mirror.SimpleWeb
  5. {
  6. /// <summary>
  7. /// Represents a client's request to the Websockets server, which is the first message from the client.
  8. /// </summary>
  9. public class Request
  10. {
  11. static readonly char[] lineSplitChars = new char[] { '\r', '\n' };
  12. static readonly char[] headerSplitChars = new char[] { ':' };
  13. public string RequestLine;
  14. public Dictionary<string, string> Headers = new Dictionary<string, string>();
  15. public Request(string message)
  16. {
  17. string[] all = message.Split(lineSplitChars, StringSplitOptions.RemoveEmptyEntries);
  18. RequestLine = all.First();
  19. Headers = all.Skip(1)
  20. .Select(header => header.Split(headerSplitChars, 2, StringSplitOptions.RemoveEmptyEntries))
  21. .ToDictionary(split => split[0].Trim(), split => split[1].Trim());
  22. }
  23. }
  24. }