HttpContentHeaders.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // HttpContentHeaders.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 HttpContentHeaders : HttpHeaders
  32. {
  33. readonly HttpContent content;
  34. internal HttpContentHeaders (HttpContent content)
  35. : base (HttpHeaderKind.Content)
  36. {
  37. this.content = content;
  38. }
  39. public ICollection<string> Allow {
  40. get {
  41. return GetValues<string> ("Allow");
  42. }
  43. }
  44. public ICollection<string> ContentEncoding {
  45. get {
  46. return GetValues<string> ("Content-Encoding");
  47. }
  48. }
  49. public ContentDispositionHeaderValue ContentDisposition {
  50. get {
  51. return GetValue<ContentDispositionHeaderValue> ("Content-Disposition");
  52. }
  53. set {
  54. AddOrRemove ("Content-Disposition", value);
  55. }
  56. }
  57. public ICollection<string> ContentLanguage {
  58. get {
  59. return GetValues<string> ("Content-Language");
  60. }
  61. }
  62. public long? ContentLength {
  63. get {
  64. long? v = GetValue<long?> ("Content-Length");
  65. if (v != null)
  66. return v;
  67. long l;
  68. if (content.TryComputeLength (out l))
  69. return l;
  70. return null;
  71. }
  72. set {
  73. AddOrRemove ("Content-Length", value);
  74. }
  75. }
  76. public Uri ContentLocation {
  77. get {
  78. return GetValue<Uri> ("Content-Location");
  79. }
  80. set {
  81. AddOrRemove ("Content-Location", value);
  82. }
  83. }
  84. public byte[] ContentMD5 {
  85. get {
  86. return GetValue<byte[]> ("Content-MD5");
  87. }
  88. set {
  89. AddOrRemove ("Content-MD5", value);
  90. }
  91. }
  92. public ContentRangeHeaderValue ContentRange {
  93. get {
  94. return GetValue<ContentRangeHeaderValue> ("Content-Range");
  95. }
  96. set {
  97. AddOrRemove ("Content-Range", value);
  98. }
  99. }
  100. public MediaTypeHeaderValue ContentType {
  101. get {
  102. return GetValue<MediaTypeHeaderValue> ("Content-Type");
  103. }
  104. set {
  105. AddOrRemove ("Content-Type", value);
  106. }
  107. }
  108. public DateTimeOffset? Expires {
  109. get {
  110. return GetValue<DateTimeOffset?> ("Expires");
  111. }
  112. set {
  113. AddOrRemove ("Expires", value, Parser.DateTime.ToString);
  114. }
  115. }
  116. public DateTimeOffset? LastModified {
  117. get {
  118. return GetValue<DateTimeOffset?> ("Last-Modified");
  119. }
  120. set {
  121. AddOrRemove ("Last-Modified", value, Parser.DateTime.ToString);
  122. }
  123. }
  124. }
  125. }