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