2 // System.Net.WebConnection
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Net.Sockets;
34 using System.Reflection;
35 using System.Security.Cryptography.X509Certificates;
37 using System.Threading;
39 using Mono.Security.Protocol.Tls;
57 object socketLock = new object ();
58 WebExceptionStatus status;
59 WaitCallback initConn;
62 static AsyncCallback readDoneDelegate = new AsyncCallback (ReadDone);
63 EventHandler abortHandler;
64 AbortHelper abortHelper;
66 internal WebConnectionData Data;
68 ChunkStream chunkStream;
73 HttpWebRequest priority_request;
74 NetworkCredential ntlm_credentials;
75 bool ntlm_authenticated;
80 Exception connect_exception;
81 static object classLock = new object ();
82 static Type sslStream;
83 static PropertyInfo piClient;
84 static PropertyInfo piServer;
85 static PropertyInfo piTrustFailure;
88 static MethodInfo start_wwan;
90 static WebConnection ()
92 Type type = Type.GetType ("MonoTouch.ObjCRuntime.Runtime, monotouch");
93 start_wwan = type.GetMethod ("StartWWAN");
97 public WebConnection (WebConnectionGroup group, ServicePoint sPoint)
100 buffer = new byte [4096];
101 readState = ReadState.None;
102 Data = new WebConnectionData ();
103 initConn = new WaitCallback (InitConnection);
105 abortHelper = new AbortHelper ();
106 abortHelper.Connection = this;
107 abortHandler = new EventHandler (abortHelper.Abort);
111 public WebConnection Connection;
113 public void Abort (object sender, EventArgs args)
115 WebConnection other = ((HttpWebRequest) sender).WebConnection;
118 other.Abort (sender, args);
124 // The real condition is !(socket.Poll (0, SelectMode.SelectRead) || socket.Available != 0)
125 // but if there's data pending to read (!) we won't reuse the socket.
126 return (socket.Poll (0, SelectMode.SelectRead) == false);
129 void Connect (HttpWebRequest request)
132 if (socket != null && socket.Connected && status == WebExceptionStatus.Success) {
133 // Take the chunked stream to the expected state (State.None)
134 if (CanReuse () && CompleteChunkedRead ()) {
141 if (socket != null) {
147 IPHostEntry hostEntry = sPoint.HostEntry;
149 if (hostEntry == null) {
151 if (start_wwan != null) {
152 start_wwan.Invoke (null, new object [1] { sPoint.Address });
153 hostEntry = sPoint.HostEntry;
155 if (hostEntry == null) {
157 status = sPoint.UsesProxy ? WebExceptionStatus.ProxyNameResolutionFailure :
158 WebExceptionStatus.NameResolutionFailure;
165 //WebConnectionData data = Data;
166 foreach (IPAddress address in hostEntry.AddressList) {
167 socket = new Socket (address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
168 IPEndPoint remote = new IPEndPoint (address, sPoint.Address.Port);
169 socket.SetSocketOption (SocketOptionLevel.Tcp, SocketOptionName.NoDelay, sPoint.UseNagleAlgorithm ? 0 : 1);
170 socket.NoDelay = !sPoint.UseNagleAlgorithm;
171 if (!sPoint.CallEndPointDelegate (socket, remote)) {
174 status = WebExceptionStatus.ConnectFailure;
179 socket.Connect (remote);
180 status = WebExceptionStatus.Success;
182 } catch (ThreadAbortException) {
183 // program exiting...
189 } catch (ObjectDisposedException) {
190 // socket closed from another thread
192 } catch (Exception exc) {
197 if (!request.Aborted)
198 status = WebExceptionStatus.ConnectFailure;
199 connect_exception = exc;
206 static void EnsureSSLStreamAvailable ()
209 if (sslStream != null)
212 #if MONOTOUCH && SECURITY_DEP
213 sslStream = typeof (Mono.Security.Protocol.Tls.HttpsClientStream);
215 // HttpsClientStream is an internal glue class in Mono.Security.dll
216 sslStream = Type.GetType ("Mono.Security.Protocol.Tls.HttpsClientStream, " +
217 Consts.AssemblyMono_Security, false);
219 if (sslStream == null) {
220 string msg = "Missing Mono.Security.dll assembly. " +
221 "Support for SSL/TLS is unavailable.";
223 throw new NotSupportedException (msg);
226 piClient = sslStream.GetProperty ("SelectedClientCertificate");
227 piServer = sslStream.GetProperty ("ServerCertificate");
228 piTrustFailure = sslStream.GetProperty ("TrustFailure");
232 bool CreateTunnel (HttpWebRequest request, Stream stream, out byte [] buffer)
234 StringBuilder sb = new StringBuilder ();
235 sb.Append ("CONNECT ");
236 sb.Append (request.Address.Host);
238 sb.Append (request.Address.Port);
239 sb.Append (" HTTP/");
240 if (request.ServicePoint.ProtocolVersion == HttpVersion.Version11)
245 sb.Append ("\r\nHost: ");
246 sb.Append (request.Address.Authority);
247 string challenge = Data.Challenge;
248 Data.Challenge = null;
249 bool have_auth = (request.Headers ["Proxy-Authorization"] != null);
251 sb.Append ("\r\nProxy-Authorization: ");
252 sb.Append (request.Headers ["Proxy-Authorization"]);
253 } else if (challenge != null && Data.StatusCode == 407) {
255 ICredentials creds = request.Proxy.Credentials;
256 Authorization auth = AuthenticationManager.Authenticate (challenge, request, creds);
258 sb.Append ("\r\nProxy-Authorization: ");
259 sb.Append (auth.Message);
262 sb.Append ("\r\n\r\n");
265 byte [] connectBytes = Encoding.Default.GetBytes (sb.ToString ());
266 stream.Write (connectBytes, 0, connectBytes.Length);
269 WebHeaderCollection result = ReadHeaders (request, stream, out buffer, out status);
270 if (!have_auth && result != null && status == 407) { // Needs proxy auth
271 Data.StatusCode = status;
272 Data.Challenge = result ["Proxy-Authenticate"];
274 } else if (status != 200) {
275 string msg = String.Format ("The remote server returned a {0} status code.", status);
276 HandleError (WebExceptionStatus.SecureChannelFailure, null, msg);
280 return (result != null);
283 WebHeaderCollection ReadHeaders (HttpWebRequest request, Stream stream, out byte [] retBuffer, out int status)
288 byte [] buffer = new byte [1024];
289 MemoryStream ms = new MemoryStream ();
290 bool gotStatus = false;
291 WebHeaderCollection headers = null;
294 int n = stream.Read (buffer, 0, 1024);
296 HandleError (WebExceptionStatus.ServerProtocolViolation, null, "ReadHeaders");
300 ms.Write (buffer, 0, n);
303 headers = new WebHeaderCollection ();
304 while (ReadLine (ms.GetBuffer (), ref start, (int) ms.Length, ref str)) {
306 if (ms.Length - start > 0) {
307 retBuffer = new byte [ms.Length - start];
308 Buffer.BlockCopy (ms.GetBuffer (), start, retBuffer, 0, retBuffer.Length);
318 int spaceidx = str.IndexOf (' ');
319 if (spaceidx == -1) {
320 HandleError (WebExceptionStatus.ServerProtocolViolation, null, "ReadHeaders2");
324 status = (int) UInt32.Parse (str.Substring (spaceidx + 1, 3));
330 bool CreateStream (HttpWebRequest request)
333 NetworkStream serverStream = new NetworkStream (socket, false);
335 if (request.Address.Scheme == Uri.UriSchemeHttps) {
337 EnsureSSLStreamAvailable ();
338 if (!reused || nstream == null || nstream.GetType () != sslStream) {
339 byte [] buffer = null;
340 if (sPoint.UseConnect) {
341 bool ok = CreateTunnel (request, serverStream, out buffer);
346 object[] args = new object [4] { serverStream,
347 request.ClientCertificates,
349 nstream = (Stream) Activator.CreateInstance (sslStream, args);
351 SslClientStream scs = (SslClientStream) nstream;
352 var helper = new ServicePointManager.ChainValidationHelper (request);
353 scs.ServerCertValidation2 += new CertificateValidationCallback2 (helper.ValidateChain);
355 certsAvailable = false;
357 // we also need to set ServicePoint.Certificate
358 // and ServicePoint.ClientCertificate but this can
359 // only be done later (after handshake - which is
360 // done only after a read operation).
363 nstream = serverStream;
365 } catch (Exception) {
366 if (!request.Aborted)
367 status = WebExceptionStatus.ConnectFailure;
374 void HandleError (WebExceptionStatus st, Exception e, string where)
378 if (st == WebExceptionStatus.RequestCanceled)
379 Data = new WebConnectionData ();
382 if (e == null) { // At least we now where it comes from
385 throw new Exception ();
387 throw new Exception (new System.Diagnostics.StackTrace ().ToString ());
389 } catch (Exception e2) {
394 HttpWebRequest req = null;
395 if (Data != null && Data.request != null)
400 req.FinishedReading = true;
401 req.SetResponseError (st, e, where);
405 static void ReadDone (IAsyncResult result)
407 WebConnection cnc = (WebConnection) result.AsyncState;
408 WebConnectionData data = cnc.Data;
409 Stream ns = cnc.nstream;
417 nread = ns.EndRead (result);
418 } catch (Exception e) {
419 cnc.HandleError (WebExceptionStatus.ReceiveFailure, e, "ReadDone1");
424 cnc.HandleError (WebExceptionStatus.ReceiveFailure, null, "ReadDone2");
429 cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, null, "ReadDone3");
434 nread += cnc.position;
435 if (cnc.readState == ReadState.None) {
436 Exception exc = null;
438 pos = cnc.GetResponse (cnc.buffer, nread);
439 } catch (Exception e) {
444 cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, exc, "ReadDone4");
449 if (cnc.readState != ReadState.Content) {
451 int max = (est < cnc.buffer.Length) ? cnc.buffer.Length : est;
452 byte [] newBuffer = new byte [max];
453 Buffer.BlockCopy (cnc.buffer, 0, newBuffer, 0, nread);
454 cnc.buffer = newBuffer;
455 cnc.position = nread;
456 cnc.readState = ReadState.None;
463 WebConnectionStream stream = new WebConnectionStream (cnc);
465 string contentType = data.Headers ["Transfer-Encoding"];
466 cnc.chunkedRead = (contentType != null && contentType.ToLower ().IndexOf ("chunked") != -1);
467 if (!cnc.chunkedRead) {
468 stream.ReadBuffer = cnc.buffer;
469 stream.ReadBufferOffset = pos;
470 stream.ReadBufferSize = nread;
471 stream.CheckResponseInBuffer ();
472 } else if (cnc.chunkStream == null) {
474 cnc.chunkStream = new ChunkStream (cnc.buffer, pos, nread, data.Headers);
475 } catch (Exception e) {
476 cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, e, "ReadDone5");
480 cnc.chunkStream.ResetBuffer ();
482 cnc.chunkStream.Write (cnc.buffer, pos, nread);
483 } catch (Exception e) {
484 cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, e, "ReadDone6");
489 data.stream = stream;
491 if (!ExpectContent (data.StatusCode) || data.request.Method == "HEAD")
492 stream.ForceCompletion ();
494 data.request.SetResponseData (data);
497 static bool ExpectContent (int statusCode)
499 return (statusCode >= 200 && statusCode != 204 && statusCode != 304);
502 internal void GetCertificates ()
504 // here the SSL negotiation have been done
505 X509Certificate client = (X509Certificate) piClient.GetValue (nstream, null);
506 X509Certificate server = (X509Certificate) piServer.GetValue (nstream, null);
507 sPoint.SetCertificates (client, server);
508 certsAvailable = (server != null);
511 internal static void InitRead (object state)
513 WebConnection cnc = (WebConnection) state;
514 Stream ns = cnc.nstream;
517 int size = cnc.buffer.Length - cnc.position;
518 ns.BeginRead (cnc.buffer, cnc.position, size, readDoneDelegate, cnc);
519 } catch (Exception e) {
520 cnc.HandleError (WebExceptionStatus.ReceiveFailure, e, "InitRead");
524 int GetResponse (byte [] buffer, int max)
529 bool isContinue = false;
530 bool emptyFirstLine = false;
532 if (readState == ReadState.None) {
533 lineok = ReadLine (buffer, ref pos, max, ref line);
538 emptyFirstLine = true;
541 emptyFirstLine = false;
543 readState = ReadState.Status;
545 string [] parts = line.Split (' ');
546 if (parts.Length < 2)
549 if (String.Compare (parts [0], "HTTP/1.1", true) == 0) {
550 Data.Version = HttpVersion.Version11;
551 sPoint.SetVersion (HttpVersion.Version11);
553 Data.Version = HttpVersion.Version10;
554 sPoint.SetVersion (HttpVersion.Version10);
557 Data.StatusCode = (int) UInt32.Parse (parts [1]);
558 if (parts.Length >= 3)
559 Data.StatusDescription = String.Join (" ", parts, 2, parts.Length - 2);
561 Data.StatusDescription = "";
567 emptyFirstLine = false;
568 if (readState == ReadState.Status) {
569 readState = ReadState.Headers;
570 Data.Headers = new WebHeaderCollection ();
571 ArrayList headers = new ArrayList ();
572 bool finished = false;
574 if (ReadLine (buffer, ref pos, max, ref line) == false)
578 // Empty line: end of headers
583 if (line.Length > 0 && (line [0] == ' ' || line [0] == '\t')) {
584 int count = headers.Count - 1;
588 string prev = (string) headers [count] + line;
589 headers [count] = prev;
598 foreach (string s in headers)
599 Data.Headers.SetInternal (s);
601 if (Data.StatusCode == (int) HttpStatusCode.Continue) {
602 sPoint.SendContinue = true;
606 if (Data.request.ExpectContinue) {
607 Data.request.DoContinueDelegate (Data.StatusCode, Data.Headers);
608 // Prevent double calls when getting the
609 // headers in several packets.
610 Data.request.ExpectContinue = false;
613 readState = ReadState.None;
617 readState = ReadState.Content;
621 } while (emptyFirstLine || isContinue);
626 void InitConnection (object state)
628 HttpWebRequest request = (HttpWebRequest) state;
629 request.WebConnection = this;
634 keepAlive = request.KeepAlive;
635 Data = new WebConnectionData ();
636 Data.request = request;
642 if (status != WebExceptionStatus.Success) {
643 if (!request.Aborted) {
644 request.SetWriteStreamError (status, connect_exception);
650 if (!CreateStream (request)) {
654 WebExceptionStatus st = status;
655 if (Data.Challenge != null)
658 Exception cnc_exc = connect_exception;
659 connect_exception = null;
660 request.SetWriteStreamError (st, cnc_exc);
665 readState = ReadState.None;
666 request.SetWriteStream (new WebConnectionStream (this, request));
669 internal EventHandler SendRequest (HttpWebRequest request)
677 status = WebExceptionStatus.Success;
678 ThreadPool.QueueUserWorkItem (initConn, request);
681 queue.Enqueue (request);
692 if (queue.Count > 0) {
693 SendRequest ((HttpWebRequest) queue.Dequeue ());
698 internal void NextRead ()
701 Data.request.FinishedReading = true;
702 string header = (sPoint.UsesProxy) ? "Proxy-Connection" : "Connection";
703 string cncHeader = (Data.Headers != null) ? Data.Headers [header] : null;
704 bool keepAlive = (Data.Version == HttpVersion.Version11 && this.keepAlive);
705 if (cncHeader != null) {
706 cncHeader = cncHeader.ToLower ();
707 keepAlive = (this.keepAlive && cncHeader.IndexOf ("keep-alive") != -1);
710 if ((socket != null && !socket.Connected) ||
711 (!keepAlive || (cncHeader != null && cncHeader.IndexOf ("close") != -1))) {
716 if (priority_request != null) {
717 SendRequest (priority_request);
718 priority_request = null;
725 static bool ReadLine (byte [] buffer, ref int start, int max, ref string output)
727 bool foundCR = false;
728 StringBuilder text = new StringBuilder ();
731 while (start < max) {
732 c = (int) buffer [start++];
734 if (c == '\n') { // newline
735 if ((text.Length > 0) && (text [text.Length - 1] == '\r'))
740 } else if (foundCR) {
749 text.Append ((char) c);
752 if (c != '\n' && c != '\r')
755 if (text.Length == 0) {
757 return (c == '\n' || c == '\r');
763 output = text.ToString ();
768 internal IAsyncResult BeginRead (HttpWebRequest request, byte [] buffer, int offset, int size, AsyncCallback cb, object state)
771 if (Data.request != request)
772 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
777 IAsyncResult result = null;
778 if (!chunkedRead || chunkStream.WantMore) {
780 result = nstream.BeginRead (buffer, offset, size, cb, state);
782 } catch (Exception) {
783 HandleError (WebExceptionStatus.ReceiveFailure, null, "chunked BeginRead");
789 WebAsyncResult wr = new WebAsyncResult (cb, state, buffer, offset, size);
790 wr.InnerAsyncResult = result;
791 if (result == null) {
792 // Will be completed from the data in ChunkStream
793 wr.SetCompleted (true, (Exception) null);
802 internal int EndRead (HttpWebRequest request, IAsyncResult result)
805 if (Data.request != request)
806 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
808 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
812 WebAsyncResult wr = null;
813 IAsyncResult nsAsync = ((WebAsyncResult) result).InnerAsyncResult;
814 if (chunkedRead && (nsAsync is WebAsyncResult)) {
815 wr = (WebAsyncResult) nsAsync;
816 IAsyncResult inner = wr.InnerAsyncResult;
817 if (inner != null && !(inner is WebAsyncResult))
818 nbytes = nstream.EndRead (inner);
819 } else if (!(nsAsync is WebAsyncResult)) {
820 nbytes = nstream.EndRead (nsAsync);
821 wr = (WebAsyncResult) result;
825 bool done = (nbytes == 0);
827 chunkStream.WriteAndReadBack (wr.Buffer, wr.Offset, wr.Size, ref nbytes);
828 if (!done && nbytes == 0 && chunkStream.WantMore)
829 nbytes = EnsureRead (wr.Buffer, wr.Offset, wr.Size);
830 } catch (Exception e) {
831 if (e is WebException)
834 throw new WebException ("Invalid chunked data.", e,
835 WebExceptionStatus.ServerProtocolViolation, null);
838 if ((done || nbytes == 0) && chunkStream.ChunkLeft != 0) {
839 HandleError (WebExceptionStatus.ReceiveFailure, null, "chunked EndRead");
840 throw new WebException ("Read error", null, WebExceptionStatus.ReceiveFailure, null);
844 return (nbytes != 0) ? nbytes : -1;
847 // To be called on chunkedRead when we can read no data from the ChunkStream yet
848 int EnsureRead (byte [] buffer, int offset, int size)
850 byte [] morebytes = null;
852 while (nbytes == 0 && chunkStream.WantMore) {
853 int localsize = chunkStream.ChunkLeft;
854 if (localsize <= 0) // not read chunk size yet
856 else if (localsize > 16384)
859 if (morebytes == null || morebytes.Length < localsize)
860 morebytes = new byte [localsize];
862 int nread = nstream.Read (morebytes, 0, localsize);
866 chunkStream.Write (morebytes, 0, nread);
867 nbytes += chunkStream.Read (buffer, offset + nbytes, size - nbytes);
873 bool CompleteChunkedRead()
875 if (!chunkedRead || chunkStream == null)
878 while (chunkStream.WantMore) {
879 int nbytes = nstream.Read (buffer, 0, buffer.Length);
881 return false; // Socket was disconnected
883 chunkStream.Write (buffer, 0, nbytes);
889 internal IAsyncResult BeginWrite (HttpWebRequest request, byte [] buffer, int offset, int size, AsyncCallback cb, object state)
892 if (Data.request != request)
893 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
898 IAsyncResult result = null;
900 result = nstream.BeginWrite (buffer, offset, size, cb, state);
901 } catch (Exception) {
902 status = WebExceptionStatus.SendFailure;
909 internal void EndWrite2 (HttpWebRequest request, IAsyncResult result)
911 if (request.FinishedReading)
915 if (Data.request != request)
916 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
918 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
922 nstream.EndWrite (result);
923 } catch (Exception exc) {
924 status = WebExceptionStatus.SendFailure;
925 if (exc.InnerException != null)
926 throw exc.InnerException;
931 internal bool EndWrite (HttpWebRequest request, IAsyncResult result)
933 if (request.FinishedReading)
937 if (Data.request != request)
938 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
940 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
944 nstream.EndWrite (result);
947 status = WebExceptionStatus.SendFailure;
952 internal int Read (HttpWebRequest request, byte [] buffer, int offset, int size)
955 if (Data.request != request)
956 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
965 result = nstream.Read (buffer, offset, size);
966 done = (result == 0);
971 chunkStream.WriteAndReadBack (buffer, offset, size, ref result);
972 if (!done && result == 0 && chunkStream.WantMore)
973 result = EnsureRead (buffer, offset, size);
974 } catch (Exception e) {
975 HandleError (WebExceptionStatus.ReceiveFailure, e, "chunked Read1");
979 if ((done || result == 0) && chunkStream.WantMore) {
980 HandleError (WebExceptionStatus.ReceiveFailure, null, "chunked Read2");
981 throw new WebException ("Read error", null, WebExceptionStatus.ReceiveFailure, null);
984 } catch (Exception e) {
985 HandleError (WebExceptionStatus.ReceiveFailure, e, "Read");
991 internal bool Write (HttpWebRequest request, byte [] buffer, int offset, int size, ref string err_msg)
995 if (Data.request != request)
996 throw new ObjectDisposedException (typeof (NetworkStream).FullName);
1002 nstream.Write (buffer, offset, size);
1003 // here SSL handshake should have been done
1004 if (ssl && !certsAvailable)
1006 } catch (Exception e) {
1007 err_msg = e.Message;
1008 WebExceptionStatus wes = WebExceptionStatus.SendFailure;
1009 string msg = "Write: " + err_msg;
1010 if (e is WebException) {
1011 HandleError (wes, e, msg);
1015 // if SSL is in use then check for TrustFailure
1016 if (ssl && (bool) piTrustFailure.GetValue (nstream, null)) {
1017 wes = WebExceptionStatus.TrustFailure;
1018 msg = "Trust failure";
1021 HandleError (wes, e, msg);
1027 internal void Close (bool sendNext)
1030 if (nstream != null) {
1037 if (socket != null) {
1045 Data = new WebConnectionData ();
1051 void Abort (object sender, EventArgs args)
1055 HttpWebRequest req = (HttpWebRequest) sender;
1056 if (Data.request == req) {
1057 if (!req.FinishedReading) {
1058 status = WebExceptionStatus.RequestCanceled;
1060 if (queue.Count > 0) {
1061 Data.request = (HttpWebRequest) queue.Dequeue ();
1062 SendRequest (Data.request);
1068 req.FinishedReading = true;
1069 req.SetResponseError (WebExceptionStatus.RequestCanceled, null, "User aborted");
1070 if (queue.Count > 0 && queue.Peek () == sender) {
1072 } else if (queue.Count > 0) {
1073 object [] old = queue.ToArray ();
1075 for (int i = old.Length - 1; i >= 0; i--) {
1076 if (old [i] != sender)
1077 queue.Enqueue (old [i]);
1084 internal void ResetNtlm ()
1086 ntlm_authenticated = false;
1087 ntlm_credentials = null;
1088 unsafe_sharing = false;
1091 internal bool Busy {
1092 get { lock (this) return busy; }
1095 internal bool Connected {
1098 return (socket != null && socket.Connected);
1103 // -Used for NTLM authentication
1104 internal HttpWebRequest PriorityRequest {
1105 set { priority_request = value; }
1108 internal bool NtlmAuthenticated {
1109 get { return ntlm_authenticated; }
1110 set { ntlm_authenticated = value; }
1113 internal NetworkCredential NtlmCredential {
1114 get { return ntlm_credentials; }
1115 set { ntlm_credentials = value; }
1118 internal bool UnsafeAuthenticatedConnectionSharing {
1119 get { return unsafe_sharing; }
1120 set { unsafe_sharing = value; }