// // HttpResponseHeaders.cs // // Authors: // Marek Safar // // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System.Collections.Generic; namespace System.Net.Http.Headers { public sealed class HttpResponseHeaders : HttpHeaders { internal HttpResponseHeaders () : base (HttpHeaderKind.Response) { } public HttpHeaderValueCollection AcceptRanges { get { return GetValues ("Accept-Ranges"); } } public TimeSpan? Age { get { return GetValue ("Age"); } set { AddOrRemove ("Age", value, l => ((long)((TimeSpan)l).TotalSeconds).ToString ()); } } public CacheControlHeaderValue CacheControl { get { return GetValue ("Cache-Control"); } set { AddOrRemove ("Cache-Control", value); } } public HttpHeaderValueCollection Connection { get { return GetValues ("Connection"); } } public bool? ConnectionClose { get { if (connectionclose == true || Connection.Find (l => string.Equals (l, "close", StringComparison.OrdinalIgnoreCase)) != null) return true; return connectionclose; } set { if (connectionclose == value) return; Connection.Remove ("close"); if (value == true) Connection.Add ("close"); connectionclose = value; } } public DateTimeOffset? Date { get { return GetValue ("Date"); } set { AddOrRemove ("Date", value, Parser.DateTime.ToString); } } public EntityTagHeaderValue ETag { get { return GetValue ("ETag"); } set { AddOrRemove ("ETag", value); } } public Uri Location { get { return GetValue ("Location"); } set { AddOrRemove ("Location", value); } } public HttpHeaderValueCollection Pragma { get { return GetValues ("Pragma"); } } public HttpHeaderValueCollection ProxyAuthenticate { get { return GetValues ("Proxy-Authenticate"); } } public RetryConditionHeaderValue RetryAfter { get { return GetValue ("Retry-After"); } set { AddOrRemove ("Retry-After", value); } } public HttpHeaderValueCollection Server { get { return GetValues ("Server"); } } public HttpHeaderValueCollection Trailer { get { return GetValues ("Trailer"); } } public HttpHeaderValueCollection TransferEncoding { get { return GetValues ("Transfer-Encoding"); } } public bool? TransferEncodingChunked { get { if (transferEncodingChunked.HasValue) return transferEncodingChunked; var found = TransferEncoding.Find (l => StringComparer.OrdinalIgnoreCase.Equals (l.Value, "chunked")); return found != null ? true : (bool?) null; } set { if (value == transferEncodingChunked) return; TransferEncoding.Remove (l => l.Value == "chunked"); if (value == true) TransferEncoding.Add (new TransferCodingHeaderValue ("chunked")); transferEncodingChunked = value; } } public HttpHeaderValueCollection Upgrade { get { return GetValues ("Upgrade"); } } public HttpHeaderValueCollection Vary { get { return GetValues ("Vary"); } } public HttpHeaderValueCollection Via { get { return GetValues ("Via"); } } public HttpHeaderValueCollection Warning { get { return GetValues ("Warning"); } } public HttpHeaderValueCollection WwwAuthenticate { get { return GetValues ("WWW-Authenticate"); } } } }