// This is the same default policy as used by the .NET 
		// framework. It accepts valid certificates and (valid
		// but) expired certificates.
		public bool CheckValidationResult (ServicePoint point, X509Certificate certificate, WebRequest request, int certificateProblem)
		{
#if SECURITY_DEP
			// If using default policy and the new callback is there, ignore this
			if (ServicePointManager.ServerCertificateValidationCallback != null)
				return true;
#endif
			switch (certificateProblem) {
				case 0:			// No error
				case -2146762495:	// CERT_E_EXPIRED 0x800B0101 (WinError.h)
					return true;
				default:
					return false;
			}
		}
Beispiel #2
0
        static async Task<int> GetResponseAsync(StreamSocketStream nstream, WebConnectionData data, ServicePoint sPoint)
        {
            var isContinue = false;
            var emptyFirstLine = false;

            using (var lineReader = new HttpLineReader(nstream))
            {
                do
                {
                    if (data.ReadState == ReadState.Aborted)
                        return -1;

                    if (data.ReadState == ReadState.None)
                    {
                        var line = await lineReader.ReadLineAsync(CancellationToken.None).ConfigureAwait(false);

                        if (null == line)
                        {
                            data.ReadState = ReadState.Aborted;
                            return 0;
                        }

                        if (string.IsNullOrEmpty(line))
                        {
                            emptyFirstLine = true;
                            continue;
                        }

                        emptyFirstLine = false;
                        data.ReadState = ReadState.Status;

                        var parts = line.Split(' ');
                        if (parts.Length < 2)
                            return -1;

                        if (string.Compare(parts[0], "HTTP/1.1", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            data.Version = HttpVersion.Version11;
                            sPoint.SetVersion(HttpVersion.Version11);
                        }
                        else
                        {
                            data.Version = HttpVersion.Version10;
                            sPoint.SetVersion(HttpVersion.Version10);
                        }

                        data.StatusCode = (int)UInt32.Parse(parts[1]);
                        if (parts.Length >= 3)
                            data.StatusDescription = string.Join(" ", parts, 2, parts.Length - 2);
                        else
                            data.StatusDescription = "";
                    }

                    emptyFirstLine = false;
                    if (data.ReadState == ReadState.Status)
                    {
                        data.ReadState = ReadState.Headers;
                        data.Headers = new WebHeaderCollection();
                        var headers = new List<string>();

                        var finished = false;

                        while (!finished)
                        {
                            var line = await lineReader.ReadLineAsync(CancellationToken.None).ConfigureAwait(false);

                            if (null == line)
                                break;

                            if (string.IsNullOrEmpty(line))
                            {
                                // Empty line: end of headers
                                finished = true;
                                continue;
                            }

                            if (line.Length > 0 && (line[0] == ' ' || line[0] == '\t'))
                            {
                                var count = headers.Count - 1;
                                if (count < 0)
                                    break;

                                var prev = headers[count] + line;
                                headers[count] = prev;
                            }
                            else
                                headers.Add(line);
                        }

                        if (!finished)
                            return 0;

                        lineReader.SyncStream();

                        foreach (var s in headers)
                            data.Headers.SetInternal(s);

                        if (data.StatusCode == (int)HttpStatusCode.Continue)
                        {
                            sPoint.SendContinue = true;

                            if (data.Request.ExpectContinue)
                            {
                                data.Request.DoContinueDelegate(data.StatusCode, data.Headers);
                                // Prevent double calls when getting the
                                // headers in several packets.
                                data.Request.ExpectContinue = false;
                            }

                            data.ReadState = ReadState.None;
                            isContinue = true;
                        }
                        else
                        {
                            data.ReadState = ReadState.Content;
                            return 1;
                        }
                    }
                } while (emptyFirstLine || isContinue);
            }

            return -1;
        }
Beispiel #3
0
        //internal ChunkStream ChunkStream
        //{
        //    get { return _chunkStream; }
        //}

        public WebConnection(IWebConnectionState wcs, ServicePoint sPoint)
        {
            _state = wcs;
            _sPoint = sPoint;
            _buffer = new byte[4096];
            Data = new WebConnectionData();
            _queue = wcs.Group.Queue;
            abortHelper = new AbortHelper
            {
                Connection = this
            };
            _abortHandler = abortHelper.Abort;
        }