/// <summary>
        /// Parses the specified HTTP header line.
        /// </summary>
        /// <param name="line">The line of the HTTP header.</param>
        /// <param name="indexOfFirstDigit">The index of the first digit in the line.</param>
        /// <param name="indexOfLastDigit">The index of the last digit in the line.</param>
        /// <returns>The type of HTTP header field.</returns>
        public HeaderFields ParseHeader(string line, int indexOfFirstDigit, int indexOfLastDigit)
        {
            this._lineNumber++;

            if (!this._firstLineIsParsed)
            {
                int indexOfHttp = line.IndexOf("TTP/");
                if (indexOfHttp < 0)
                {
                    throw GenuineExceptions.Get_Receive_IncorrectData();
                }

                this._firstLineIsParsed = true;
                this._isHttp11          = line.Substring(indexOfHttp + 4, 3).CompareTo("1.1") == 0;

                if (line.IndexOf("409", indexOfHttp + 1) >= 0)
                {
                    throw GenuineExceptions.Get_Receive_ConflictOfConnections();
                }

                return(HeaderFields.FirstLine);
            }

            if (this._client && !_firstLineIsParsed)
            {
                throw GenuineExceptions.Get_Receive_IncorrectData();
            }

            if (!this._contentLengthIsParsed && line.IndexOf("CONTENT-LENGTH") >= 0)
            {
                this._contentLength = Convert.ToInt64(line.Substring(indexOfFirstDigit, indexOfLastDigit - indexOfFirstDigit + 1));
                return(HeaderFields.ContentLength);
            }

            if (!this._client)
            {
                int indexOfExpect;
                if (!this._http11_100continueIsParsed && (indexOfExpect = line.IndexOf("EXPECT")) >= 0 && line.IndexOf("100", indexOfExpect + 1) >= 0)
                {
                    this._http11_100continueIsParsed = true;
                    this._http11_100Continue         = true;

                    return(HeaderFields.Expect100Continue);
                }
            }

            if (this._lineNumber > 30)
            {
                throw GenuineExceptions.Get_Receive_IncorrectData();
            }

            return(HeaderFields.OtherField);
        }
Exemple #2
0
        /// <summary>
        /// Adds an element to the collection associated with the specified key.
        /// Ensures that there is the only instance of the element in the collection.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="hostInformation">The element being stored.</param>
        private void SetHostInformation(string key, HostInformation hostInformation)
        {
            lock (this.SyncRoot)
            {
                ArrayList arrayList = this._hashtable[key] as ArrayList;

                // if there is no collection corresponding to the key
                if (arrayList == null)
                {
                    arrayList            = new ArrayList();
                    this._hashtable[key] = arrayList;
                    arrayList.Add(hostInformation);
                    return;
                }

                // check whether this element is already in the collection
                for (int i = 0; i < arrayList.Count; i++)
                {
                    if (object.ReferenceEquals(arrayList[i], hostInformation))
                    {
                        return;
                    }

                    // TODO: What to do with this fix?! It does work, but only in really unusual circumstances.
                    // remove all HostInformations with empty URI, if the current hostInformation contains the URI
                    HostInformation currentHostInformation = (HostInformation)arrayList[i];
                    if (hostInformation.Url != null && currentHostInformation.Url == null &&
                        hostInformation.Uri == currentHostInformation.Uri && currentHostInformation.RemoteHostUniqueIdentifier == -1)
                    {
                        arrayList.RemoveAt(i);
                        arrayList.Add(hostInformation);
                        currentHostInformation.Dispose(GenuineExceptions.Get_Receive_ConflictOfConnections());
                        return;
                    }
                }

                arrayList.Add(hostInformation);
            }
        }