HttpContentHeaders.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. v = content.LoadedBufferLength;
  68. if (v != null)
  69. return v;
  70. long l;
  71. if (content.TryComputeLength (out l))
  72. return l;
  73. return null;
  74. }
  75. set {
  76. AddOrRemove ("Content-Length", value);
  77. }
  78. }
  79. public Uri ContentLocation {
  80. get {
  81. return GetValue<Uri> ("Content-Location");
  82. }
  83. set {
  84. AddOrRemove ("Content-Location", value);
  85. }
  86. }
  87. public byte[] ContentMD5 {
  88. get {
  89. return GetValue<byte[]> ("Content-MD5");
  90. }
  91. set {
  92. AddOrRemove ("Content-MD5", value);
  93. }
  94. }
  95. public ContentRangeHeaderValue ContentRange {
  96. get {
  97. return GetValue<ContentRangeHeaderValue> ("Content-Range");
  98. }
  99. set {
  100. AddOrRemove ("Content-Range", value);
  101. }
  102. }
  103. public MediaTypeHeaderValue ContentType {
  104. get {
  105. return GetValue<MediaTypeHeaderValue> ("Content-Type");
  106. }
  107. set {
  108. AddOrRemove ("Content-Type", value);
  109. }
  110. }
  111. public DateTimeOffset? Expires {
  112. get {
  113. return GetValue<DateTimeOffset?> ("Expires");
  114. }
  115. set {
  116. AddOrRemove ("Expires", value, Parser.DateTime.ToString);
  117. }
  118. }
  119. public DateTimeOffset? LastModified {
  120. get {
  121. return GetValue<DateTimeOffset?> ("Last-Modified");
  122. }
  123. set {
  124. AddOrRemove ("Last-Modified", value, Parser.DateTime.ToString);
  125. }
  126. }
  127. }
  128. }