HttpResponseHeaders.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // HttpResponseHeaders.cs
  3. //
  4. // Authors:
  5. // Marek Safar <[email protected]>
  6. //
  7. // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.Collections.Generic;
  29. namespace System.Net.Http.Headers
  30. {
  31. public sealed class HttpResponseHeaders : HttpHeaders
  32. {
  33. internal HttpResponseHeaders ()
  34. : base (HttpHeaderKind.Response)
  35. {
  36. }
  37. public HttpHeaderValueCollection<string> AcceptRanges {
  38. get {
  39. return GetValues<string> ("Accept-Ranges");
  40. }
  41. }
  42. public TimeSpan? Age {
  43. get {
  44. return GetValue<TimeSpan?> ("Age");
  45. }
  46. set {
  47. AddOrRemove ("Age", value);
  48. }
  49. }
  50. public CacheControlHeaderValue CacheControl {
  51. get {
  52. return GetValue<CacheControlHeaderValue> ("Cache-Control");
  53. }
  54. set {
  55. AddOrRemove ("Cache-Control", value);
  56. }
  57. }
  58. public HttpHeaderValueCollection<string> Connection {
  59. get {
  60. return GetValues<string> ("Connection");
  61. }
  62. }
  63. public bool? ConnectionClose {
  64. get {
  65. if (!Contains ("Connection"))
  66. return null;
  67. var col = Connection;
  68. if (col == null)
  69. return null;
  70. return Connection.Contains ("close");
  71. }
  72. set {
  73. Connection.Remove ("close");
  74. if (value == true)
  75. Connection.Add ("close");
  76. }
  77. }
  78. public DateTimeOffset? Date {
  79. get {
  80. return GetValue<DateTimeOffset?> ("Date");
  81. }
  82. set {
  83. AddOrRemove ("Date", value);
  84. }
  85. }
  86. public EntityTagHeaderValue ETag {
  87. get {
  88. return GetValue<EntityTagHeaderValue> ("ETag");
  89. }
  90. set {
  91. AddOrRemove ("ETag", value);
  92. }
  93. }
  94. public Uri Location {
  95. get {
  96. return GetValue<Uri> ("Location");
  97. }
  98. set {
  99. AddOrRemove ("Location", value);
  100. }
  101. }
  102. public HttpHeaderValueCollection<NameValueHeaderValue> Pragma {
  103. get {
  104. return GetValues<NameValueHeaderValue> ("Pragma");
  105. }
  106. }
  107. public HttpHeaderValueCollection<AuthenticationHeaderValue> ProxyAuthenticate {
  108. get {
  109. return GetValues<AuthenticationHeaderValue> ("Proxy-Authenticate");
  110. }
  111. }
  112. public RetryConditionHeaderValue RetryAfter {
  113. get {
  114. return GetValue<RetryConditionHeaderValue> ("Retry-After");
  115. }
  116. set {
  117. AddOrRemove ("Retry-After", value);
  118. }
  119. }
  120. public HttpHeaderValueCollection<ProductInfoHeaderValue> Server {
  121. get {
  122. return GetValues<ProductInfoHeaderValue> ("Server");
  123. }
  124. }
  125. public HttpHeaderValueCollection<string> Trailer {
  126. get {
  127. return GetValues<string> ("Trailer");
  128. }
  129. }
  130. public HttpHeaderValueCollection<TransferCodingHeaderValue> TransferEncoding {
  131. get {
  132. return GetValues<TransferCodingHeaderValue> ("Transfer-Encoding");
  133. }
  134. }
  135. public bool? TransferEncodingChunked {
  136. get {
  137. if (!Contains ("Transfer-Encoding"))
  138. return null;
  139. var col = TransferEncoding;
  140. if (col == null)
  141. return null;
  142. return TransferEncoding.Find (l => StringComparer.OrdinalIgnoreCase.Equals (l.Value, "chunked")) != null;
  143. }
  144. set {
  145. TransferEncoding.Remove (l => l.Value == "chunked");
  146. if (value == true)
  147. TransferEncoding.Add (new TransferCodingHeaderValue ("chunked"));
  148. }
  149. }
  150. public HttpHeaderValueCollection<ProductHeaderValue> Upgrade {
  151. get {
  152. return GetValues<ProductHeaderValue> ("Upgrade");
  153. }
  154. }
  155. public HttpHeaderValueCollection<string> Vary {
  156. get {
  157. return GetValues<string> ("Vary");
  158. }
  159. }
  160. public HttpHeaderValueCollection<ViaHeaderValue> Via {
  161. get {
  162. return GetValues<ViaHeaderValue> ("Via");
  163. }
  164. }
  165. public HttpHeaderValueCollection<WarningHeaderValue> Warning {
  166. get {
  167. return GetValues<WarningHeaderValue> ("Warning");
  168. }
  169. }
  170. public HttpHeaderValueCollection<AuthenticationHeaderValue> WwwAuthenticate {
  171. get {
  172. return GetValues<AuthenticationHeaderValue> ("WWW-Authenticate");
  173. }
  174. }
  175. }
  176. }