[runtime] Don't leak method header (significant leak size) in aot compiler
[mono-project.git] / mcs / class / System.Net.Http / System.Net.Http.Headers / HttpRequestHeaders.cs
blob4f6ceeef8e96102c57d94a4f3714ec3ea9fd6b3c
1 //
2 // HttpRequestHeaders.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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System.Collections.Generic;
31 namespace System.Net.Http.Headers
33 public sealed class HttpRequestHeaders : HttpHeaders
35 bool? expectContinue;
37 internal HttpRequestHeaders ()
38 : base (HttpHeaderKind.Request)
42 public HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> Accept {
43 get {
44 return GetValues<MediaTypeWithQualityHeaderValue> ("Accept");
48 public HttpHeaderValueCollection<StringWithQualityHeaderValue> AcceptCharset {
49 get {
50 return GetValues<StringWithQualityHeaderValue> ("Accept-Charset");
54 public HttpHeaderValueCollection<StringWithQualityHeaderValue> AcceptEncoding {
55 get {
56 return GetValues<StringWithQualityHeaderValue> ("Accept-Encoding");
60 public HttpHeaderValueCollection<StringWithQualityHeaderValue> AcceptLanguage {
61 get {
62 return GetValues<StringWithQualityHeaderValue> ("Accept-Language");
66 public AuthenticationHeaderValue Authorization {
67 get {
68 return GetValue<AuthenticationHeaderValue> ("Authorization");
70 set {
71 AddOrRemove ("Authorization", value);
75 public CacheControlHeaderValue CacheControl {
76 get {
77 return GetValue<CacheControlHeaderValue> ("Cache-Control");
79 set {
80 AddOrRemove ("Cache-Control", value);
84 public HttpHeaderValueCollection<string> Connection {
85 get {
86 return GetValues<string> ("Connection");
90 public bool? ConnectionClose {
91 get {
92 if (connectionclose == true || Connection.Find (l => string.Equals (l, "close", StringComparison.OrdinalIgnoreCase)) != null)
93 return true;
95 return connectionclose;
97 set {
98 if (connectionclose == value)
99 return;
101 Connection.Remove ("close");
102 if (value == true)
103 Connection.Add ("close");
105 connectionclose = value;
109 internal bool ConnectionKeepAlive {
110 get {
111 return Connection.Find (l => string.Equals (l, "Keep-Alive", StringComparison.OrdinalIgnoreCase)) != null;
115 public DateTimeOffset? Date {
116 get {
117 return GetValue<DateTimeOffset?> ("Date");
119 set {
120 AddOrRemove ("Date", value, Parser.DateTime.ToString);
124 public HttpHeaderValueCollection<NameValueWithParametersHeaderValue> Expect {
125 get {
126 return GetValues<NameValueWithParametersHeaderValue> ("Expect");
130 public bool? ExpectContinue {
131 get {
132 if (expectContinue.HasValue)
133 return expectContinue;
135 var found = TransferEncoding.Find (l => string.Equals (l.Value, "100-continue", StringComparison.OrdinalIgnoreCase));
136 return found != null ? true : (bool?) null;
138 set {
139 if (expectContinue == value)
140 return;
142 Expect.Remove (l => l.Name == "100-continue");
144 if (value == true)
145 Expect.Add (new NameValueWithParametersHeaderValue ("100-continue"));
147 expectContinue = value;
151 public string From {
152 get {
153 return GetValue<string> ("From");
155 set {
156 if (!string.IsNullOrEmpty (value) && !Parser.EmailAddress.TryParse (value, out value))
157 throw new FormatException ();
159 AddOrRemove ("From", value);
163 public string Host {
164 get {
165 return GetValue<string> ("Host");
167 set {
168 AddOrRemove ("Host", value);
172 public HttpHeaderValueCollection<EntityTagHeaderValue> IfMatch {
173 get {
174 return GetValues<EntityTagHeaderValue> ("If-Match");
178 public DateTimeOffset? IfModifiedSince {
179 get {
180 return GetValue<DateTimeOffset?> ("If-Modified-Since");
182 set {
183 AddOrRemove ("If-Modified-Since", value, Parser.DateTime.ToString);
187 public HttpHeaderValueCollection<EntityTagHeaderValue> IfNoneMatch {
188 get {
189 return GetValues<EntityTagHeaderValue> ("If-None-Match");
193 public RangeConditionHeaderValue IfRange {
194 get {
195 return GetValue<RangeConditionHeaderValue> ("If-Range");
197 set {
198 AddOrRemove ("If-Range", value);
202 public DateTimeOffset? IfUnmodifiedSince {
203 get {
204 return GetValue<DateTimeOffset?> ("If-Unmodified-Since");
206 set {
207 AddOrRemove ("If-Unmodified-Since", value, Parser.DateTime.ToString);
211 public int? MaxForwards {
212 get {
213 return GetValue<int?> ("Max-Forwards");
215 set {
216 AddOrRemove ("Max-Forwards", value);
220 public HttpHeaderValueCollection<NameValueHeaderValue> Pragma {
221 get {
222 return GetValues<NameValueHeaderValue> ("Pragma");
226 public AuthenticationHeaderValue ProxyAuthorization {
227 get {
228 return GetValue<AuthenticationHeaderValue> ("Proxy-Authorization");
230 set {
231 AddOrRemove ("Proxy-Authorization", value);
235 public RangeHeaderValue Range {
236 get {
237 return GetValue<RangeHeaderValue> ("Range");
239 set {
240 AddOrRemove ("Range", value);
244 public Uri Referrer {
245 get {
246 return GetValue<Uri> ("Referer");
248 set {
249 AddOrRemove ("Referer", value);
253 public HttpHeaderValueCollection<TransferCodingWithQualityHeaderValue> TE {
254 get {
255 return GetValues<TransferCodingWithQualityHeaderValue> ("TE");
259 public HttpHeaderValueCollection<string> Trailer {
260 get {
261 return GetValues<string> ("Trailer");
265 public HttpHeaderValueCollection<TransferCodingHeaderValue> TransferEncoding {
266 get {
267 return GetValues<TransferCodingHeaderValue> ("Transfer-Encoding");
271 public bool? TransferEncodingChunked {
272 get {
273 if (transferEncodingChunked.HasValue)
274 return transferEncodingChunked;
276 var found = TransferEncoding.Find (l => string.Equals (l.Value, "chunked", StringComparison.OrdinalIgnoreCase));
277 return found != null ? true : (bool?) null;
279 set {
280 if (value == transferEncodingChunked)
281 return;
283 TransferEncoding.Remove (l => l.Value == "chunked");
284 if (value == true)
285 TransferEncoding.Add (new TransferCodingHeaderValue ("chunked"));
287 transferEncodingChunked = value;
291 public HttpHeaderValueCollection<ProductHeaderValue> Upgrade {
292 get {
293 return GetValues<ProductHeaderValue> ("Upgrade");
297 public HttpHeaderValueCollection<ProductInfoHeaderValue> UserAgent {
298 get {
299 return GetValues<ProductInfoHeaderValue> ("User-Agent");
303 public HttpHeaderValueCollection<ViaHeaderValue> Via {
304 get {
305 return GetValues<ViaHeaderValue> ("Via");
309 public HttpHeaderValueCollection<WarningHeaderValue> Warning {
310 get {
311 return GetValues<WarningHeaderValue> ("Warning");
315 internal void AddHeaders (HttpRequestHeaders headers)
317 foreach (var header in headers) {
318 TryAddWithoutValidation (header.Key, header.Value);