HttpHeaderInfo.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #region License
  2. /*
  3. * HttpHeaderInfo.cs
  4. *
  5. * The MIT License
  6. *
  7. * Copyright (c) 2013-2020 sta.blockhead
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. #endregion
  28. using System;
  29. namespace WebSocketSharp.Net
  30. {
  31. internal class HttpHeaderInfo
  32. {
  33. #region Private Fields
  34. private string _headerName;
  35. private HttpHeaderType _headerType;
  36. #endregion
  37. #region Internal Constructors
  38. internal HttpHeaderInfo (string headerName, HttpHeaderType headerType)
  39. {
  40. _headerName = headerName;
  41. _headerType = headerType;
  42. }
  43. #endregion
  44. #region Internal Properties
  45. internal bool IsMultiValueInRequest {
  46. get {
  47. var headerType = _headerType & HttpHeaderType.MultiValueInRequest;
  48. return headerType == HttpHeaderType.MultiValueInRequest;
  49. }
  50. }
  51. internal bool IsMultiValueInResponse {
  52. get {
  53. var headerType = _headerType & HttpHeaderType.MultiValueInResponse;
  54. return headerType == HttpHeaderType.MultiValueInResponse;
  55. }
  56. }
  57. #endregion
  58. #region Public Properties
  59. public string HeaderName {
  60. get {
  61. return _headerName;
  62. }
  63. }
  64. public HttpHeaderType HeaderType {
  65. get {
  66. return _headerType;
  67. }
  68. }
  69. public bool IsRequest {
  70. get {
  71. var headerType = _headerType & HttpHeaderType.Request;
  72. return headerType == HttpHeaderType.Request;
  73. }
  74. }
  75. public bool IsResponse {
  76. get {
  77. var headerType = _headerType & HttpHeaderType.Response;
  78. return headerType == HttpHeaderType.Response;
  79. }
  80. }
  81. #endregion
  82. #region Public Methods
  83. public bool IsMultiValue (bool response)
  84. {
  85. var headerType = _headerType & HttpHeaderType.MultiValue;
  86. if (headerType != HttpHeaderType.MultiValue)
  87. return response ? IsMultiValueInResponse : IsMultiValueInRequest;
  88. return response ? IsResponse : IsRequest;
  89. }
  90. public bool IsRestricted (bool response)
  91. {
  92. var headerType = _headerType & HttpHeaderType.Restricted;
  93. if (headerType != HttpHeaderType.Restricted)
  94. return false;
  95. return response ? IsResponse : IsRequest;
  96. }
  97. #endregion
  98. }
  99. }