Implements System.Net.Http MultipartContent
[mono.git] / mcs / class / System.Net.Http / System.Net.Http.Headers / HttpContentHeaders.cs
1 //
2 // HttpContentHeaders.cs
3 //
4 // Authors:
5 //      Marek Safar  <marek.safar@gmail.com>
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
29 using System.Collections.Generic;
30
31 namespace System.Net.Http.Headers
32 {
33         public sealed class HttpContentHeaders : HttpHeaders
34         {
35                 readonly HttpContent content;
36
37                 internal HttpContentHeaders (HttpContent content)
38                         : base (HttpHeaderKind.Content)
39                 {
40                         this.content = content;
41                 }
42                 
43                 public ICollection<string> Allow {
44                         get {
45                                 return GetValues<string> ("Allow");
46                         }
47                 }
48
49                 public ICollection<string> ContentEncoding {
50                         get {
51                                 return GetValues<string> ("Content-Encoding");
52                         }
53                 }
54                 
55                 public ContentDispositionHeaderValue ContentDisposition {
56                         get {
57                                 return GetValue<ContentDispositionHeaderValue> ("Content-Disposition");
58                         }
59                         set {
60                                 AddOrRemove ("Content-Disposition", value);
61                         }
62                 }
63
64                 public ICollection<string> ContentLanguage {
65                         get {
66                                 return GetValues<string> ("Content-Language");
67                         }
68                 }
69
70                 public long? ContentLength {
71                         get {
72                                 long? v = GetValue<long?> ("Content-Length");
73                                 if (v != null)
74                                         return v;
75
76                                 long l;
77                                 if (content.TryComputeLength (out l))
78                                         return l;
79
80                                 return null;
81                         }
82                         set {
83                                 AddOrRemove ("Content-Length", value);
84                         }
85                 }
86
87                 public Uri ContentLocation {
88                         get {
89                                 return GetValue<Uri> ("Content-Location");
90                         }
91                         set {
92                                 AddOrRemove ("Content-Location", value);
93                         }
94                 }
95
96                 public byte[] ContentMD5 {
97                         get {
98                                 return GetValue<byte[]> ("Content-MD5");
99                         }
100                         set {
101                                 AddOrRemove ("Content-MD5", value);
102                         }
103                 }
104
105                 public ContentRangeHeaderValue ContentRange {
106                         get {
107                                 return GetValue<ContentRangeHeaderValue> ("Content-Range");
108                         }
109                         set {
110                                 AddOrRemove ("Content-Range", value);
111                         }
112                 }
113
114                 public MediaTypeHeaderValue ContentType {
115                         get {
116                                 return GetValue<MediaTypeHeaderValue> ("Content-Type");
117                         }
118                         set {
119                                 AddOrRemove ("Content-Type", value);
120                         }
121                 }
122
123                 public DateTimeOffset? Expires {
124                         get {
125                                 return GetValue<DateTimeOffset?> ("Expires");
126                         }
127                         set {
128                                 AddOrRemove ("Expires", value, Parser.DateTime.ToString);
129                         }
130                 }
131
132                 public DateTimeOffset? LastModified {
133                         get {
134                                 return GetValue<DateTimeOffset?> ("Last-Modified");
135                         }
136                         set {
137                                 AddOrRemove ("Last-Modified", value, Parser.DateTime.ToString);
138                         }
139                 }
140         }
141 }