2 // WebRequestHandler.cs
5 // Martin Baulig <martin.baulig@xamarin.com>
7 // Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 using System.Net.Cache;
28 using System.Net.Security;
29 using System.Security.Principal;
30 using System.Security.Cryptography.X509Certificates;
32 namespace System.Net.Http
34 public class WebRequestHandler : HttpClientHandler
37 RequestCachePolicy cachePolicy;
38 AuthenticationLevel authenticationLevel;
39 TimeSpan continueTimeout;
40 TokenImpersonationLevel impersonationLevel;
41 int maxResponseHeadersLength;
43 RemoteCertificateValidationCallback serverCertificateValidationCallback;
44 bool unsafeAuthenticatedConnectionSharing;
46 public WebRequestHandler ()
48 allowPipelining = true;
49 authenticationLevel = AuthenticationLevel.MutualAuthRequested;
50 cachePolicy = System.Net.WebRequest.DefaultCachePolicy;
51 continueTimeout = TimeSpan.FromMilliseconds (350);
52 impersonationLevel = TokenImpersonationLevel.Delegation;
53 maxResponseHeadersLength = HttpWebRequest.DefaultMaximumResponseHeadersLength;
54 readWriteTimeout = 300000;
55 serverCertificateValidationCallback = null;
56 unsafeAuthenticatedConnectionSharing = false;
59 public bool AllowPipelining {
60 get { return allowPipelining; }
62 EnsureModifiability ();
63 allowPipelining = value;
67 public RequestCachePolicy CachePolicy {
68 get { return cachePolicy; }
70 EnsureModifiability ();
75 public AuthenticationLevel AuthenticationLevel {
76 get { return authenticationLevel; }
78 EnsureModifiability ();
79 authenticationLevel = value;
84 public X509CertificateCollection ClientCertificates {
85 get { throw new NotImplementedException (); }
89 public TimeSpan ContinueTimeout {
90 get { return continueTimeout; }
92 EnsureModifiability ();
93 continueTimeout = value;
97 public TokenImpersonationLevel ImpersonationLevel {
98 get { return impersonationLevel; }
100 EnsureModifiability ();
101 impersonationLevel = value;
105 public int MaxResponseHeadersLength {
106 get { return maxResponseHeadersLength; }
108 EnsureModifiability ();
109 maxResponseHeadersLength = value;
113 public int ReadWriteTimeout {
114 get { return readWriteTimeout; }
116 EnsureModifiability ();
117 readWriteTimeout = value;
122 public RemoteCertificateValidationCallback ServerCertificateValidationCallback {
123 get { return serverCertificateValidationCallback; }
125 EnsureModifiability ();
126 serverCertificateValidationCallback = value;
130 public bool UnsafeAuthenticatedConnectionSharing {
131 get { return unsafeAuthenticatedConnectionSharing; }
133 EnsureModifiability ();
134 unsafeAuthenticatedConnectionSharing = value;
138 internal override HttpWebRequest CreateWebRequest (HttpRequestMessage request)
140 HttpWebRequest wr = base.CreateWebRequest (request);
142 wr.Pipelined = allowPipelining;
143 wr.AuthenticationLevel = authenticationLevel;
144 wr.CachePolicy = cachePolicy;
145 wr.ImpersonationLevel = impersonationLevel;
146 wr.MaximumResponseHeadersLength = maxResponseHeadersLength;
147 wr.ReadWriteTimeout = readWriteTimeout;
148 wr.UnsafeAuthenticatedConnectionSharing = unsafeAuthenticatedConnectionSharing;