Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / System.Net.Http / System.Net.Http.Headers / HttpResponseHeaders.cs
1 //
2 // HttpResponseHeaders.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 HttpResponseHeaders : HttpHeaders
34         {
35                 internal HttpResponseHeaders ()
36                         : base (HttpHeaderKind.Response)
37                 {
38                 }
39
40                 public HttpHeaderValueCollection<string> AcceptRanges {
41                         get {
42                                 return GetValues<string> ("Accept-Ranges");
43                         }
44                 }
45
46                 public TimeSpan? Age {
47                         get {
48                                 return GetValue<TimeSpan?> ("Age");
49                         }
50                         set {
51                                 AddOrRemove ("Age", value, l => ((long)((TimeSpan)l).TotalSeconds).ToString ()); 
52                         }
53                 }
54
55                 public CacheControlHeaderValue CacheControl {
56                         get {
57                                 return GetValue<CacheControlHeaderValue> ("Cache-Control");
58                         }
59                         set {
60                                 AddOrRemove ("Cache-Control", value);
61                         }
62                 }
63
64                 public HttpHeaderValueCollection<string> Connection {
65                         get {
66                                 return GetValues<string> ("Connection");
67                         }
68                 }
69
70                 public bool? ConnectionClose {
71                         get {
72                                 if (connectionclose == true || Connection.Find (l => string.Equals (l, "close", StringComparison.OrdinalIgnoreCase)) != null)
73                                         return true;
74
75                                 return connectionclose;
76                         }
77                         set {
78                                 if (connectionclose == value)
79                                         return;
80
81                                 Connection.Remove ("close");
82                                 if (value == true)
83                                         Connection.Add ("close");
84
85                                 connectionclose = value;
86                         }
87                 }
88
89                 public DateTimeOffset? Date {
90                         get {
91                                 return GetValue<DateTimeOffset?> ("Date");
92                         }
93                         set {
94                                 AddOrRemove ("Date", value, Parser.DateTime.ToString);
95                         }
96                 }
97
98                 public EntityTagHeaderValue ETag {
99                         get {
100                                 return GetValue<EntityTagHeaderValue> ("ETag");
101                         }
102                         set {
103                                 AddOrRemove ("ETag", value);
104                         }
105                 }
106
107                 public Uri Location {
108                         get {
109                                 return GetValue<Uri> ("Location");
110                         }
111                         set {
112                                 AddOrRemove ("Location", value);
113                         }
114                 }
115
116                 public HttpHeaderValueCollection<NameValueHeaderValue> Pragma {
117                         get {
118                                 return GetValues<NameValueHeaderValue> ("Pragma");
119                         }
120                 }
121
122                 public HttpHeaderValueCollection<AuthenticationHeaderValue> ProxyAuthenticate {
123                         get {
124                                 return GetValues<AuthenticationHeaderValue> ("Proxy-Authenticate");
125                         }
126                 }
127
128                 public RetryConditionHeaderValue RetryAfter {
129                         get {
130                                 return GetValue<RetryConditionHeaderValue> ("Retry-After");
131                         }
132                         set {
133                                 AddOrRemove ("Retry-After", value);
134                         }
135                 }
136
137                 public HttpHeaderValueCollection<ProductInfoHeaderValue> Server {
138                         get {
139                                 return GetValues<ProductInfoHeaderValue> ("Server");
140                         }
141                 }
142
143                 public HttpHeaderValueCollection<string> Trailer {
144                         get {
145                                 return GetValues<string> ("Trailer");
146                         }
147                 }
148
149                 public HttpHeaderValueCollection<TransferCodingHeaderValue> TransferEncoding {
150                         get {
151                                 return GetValues<TransferCodingHeaderValue> ("Transfer-Encoding");
152                         }
153                 }
154
155                 public bool? TransferEncodingChunked {
156                         get {
157                                 if (transferEncodingChunked.HasValue)
158                                         return transferEncodingChunked;
159
160                                 var found = TransferEncoding.Find (l => StringComparer.OrdinalIgnoreCase.Equals (l.Value, "chunked"));
161                                 return found != null ? true : (bool?) null;
162                         }
163                         set {
164                                 if (value == transferEncodingChunked)
165                                         return;
166
167                                 TransferEncoding.Remove (l => l.Value == "chunked");
168                                 if (value == true)
169                                         TransferEncoding.Add (new TransferCodingHeaderValue ("chunked"));
170
171                                 transferEncodingChunked = value;
172                         }
173                 }
174
175                 public HttpHeaderValueCollection<ProductHeaderValue> Upgrade {
176                         get {
177                                 return GetValues<ProductHeaderValue> ("Upgrade");
178                         }
179                 }
180
181                 public HttpHeaderValueCollection<string> Vary {
182                         get {
183                                 return GetValues<string> ("Vary");
184                         }
185                 }
186
187                 public HttpHeaderValueCollection<ViaHeaderValue> Via {
188                         get {
189                                 return GetValues<ViaHeaderValue> ("Via");
190                         }
191                 }
192
193                 public HttpHeaderValueCollection<WarningHeaderValue> Warning {
194                         get {
195                                 return GetValues<WarningHeaderValue> ("Warning");
196                         }
197                 }
198
199                 public HttpHeaderValueCollection<AuthenticationHeaderValue> WwwAuthenticate {
200                         get {
201                                 return GetValues<AuthenticationHeaderValue> ("WWW-Authenticate");
202                         }
203                 }
204         }
205 }