Example #1
0
		public Boolean ReadHeader(Connection connection)
		{
			this.FirstHeader = String.Empty;

			String lStart = HttpHeaders.ReadHttpMethodName(connection);

			if (lStart == null)
				return false;

			if (String.Equals(lStart, String.Empty, StringComparison.Ordinal))
				throw new HttpRequestInvalidException(HttpStatusCode.InternalServerError, "Invalid HTTP Request, 'POST', 'MERGE', 'GET', 'DELETE', 'PUT' or 'HEAD' header expected.");

			String lHeaderLine;
			do
			{
				lHeaderLine = connection.ReadLine();

				if (!String.IsNullOrEmpty(lHeaderLine))
				{
					if (this.FirstHeader.Length == 0)
					{
						this.FirstHeader = lStart + lHeaderLine;
					}
					else
					{
						Int32 lPos = lHeaderLine.IndexOf(":", StringComparison.Ordinal);
						if (lPos == -1)
						{
							throw new HttpHeaderException("Invalid HTTP Header Line \"" + lHeaderLine + "\"");
						}

						String lName = lHeaderLine.Substring(0, lPos);
						String lValue = null;

						// There should be a space after the ":" , but at least one custome said that this is not
						// always true
						// So we check if there is space after the ":"
						if (lHeaderLine.Length > lPos + 1)
						{
							if (lHeaderLine[lPos + 1] == ' ')
								lValue = lHeaderLine.Substring(lPos + 2);
							else
								lValue = lHeaderLine.Substring(lPos + 1);
						}

						HttpHeader lHeader = this[lName];
						if (lHeader == null)
						{
							lHeader = new HttpHeader(lName, lValue);
							fHeaders.Add(lName, lHeader);
						}
						else
						{
							lHeader.Add(lValue);
						}
					}
				}

				if (this.MaxHeaderLinesEnabled && this.fHeaders.Count > this.MaxHeaderLines - 1) // -1 because FirstHeader is not in hashtable
				{
					connection.Disconnect();
					throw new HttpHeaderException(String.Format("Too many header lines received (maximum is set to {0})", MaxHeaderLines));
				}
			}
			while (!String.IsNullOrEmpty(lHeaderLine));

			this.ParseFirstLine();

			return true;
		}
Example #2
0
		public void SetHeaderValue(String name, String value)
		{
			HttpHeader lHeader = this[name];

			if (lHeader == null)
			{
				lHeader = new HttpHeader(name, value);
				fHeaders[name] = lHeader;
			}
			else
			{
				lHeader.Value = value;
			}
		}
Example #3
0
        public Boolean ReadHeader(Connection connection)
        {
            this.FirstHeader = String.Empty;

            String lStart = HttpHeaders.ReadHttpMethodName(connection);

            if (lStart == null)
            {
                return(false);
            }

            if (String.Equals(lStart, String.Empty, StringComparison.Ordinal))
            {
                throw new HttpRequestInvalidException(HttpStatusCode.InternalServerError, "Invalid HTTP Request, 'POST', 'MERGE', 'GET', 'DELETE', 'PUT' or 'HEAD' header expected.");
            }

            String lHeaderLine;

            do
            {
                lHeaderLine = connection.ReadLine();

                if (!String.IsNullOrEmpty(lHeaderLine))
                {
                    if (this.FirstHeader.Length == 0)
                    {
                        this.FirstHeader = lStart + lHeaderLine;
                    }
                    else
                    {
                        Int32 lPos = lHeaderLine.IndexOf(":", StringComparison.Ordinal);
                        if (lPos == -1)
                        {
                            throw new HttpHeaderException("Invalid HTTP Header Line \"" + lHeaderLine + "\"");
                        }

                        String lName  = lHeaderLine.Substring(0, lPos);
                        String lValue = null;

                        // There should be a space after the ":" , but at least one custome said that this is not
                        // always true
                        // So we check if there is space after the ":"
                        if (lHeaderLine.Length > lPos + 1)
                        {
                            if (lHeaderLine[lPos + 1] == ' ')
                            {
                                lValue = lHeaderLine.Substring(lPos + 2);
                            }
                            else
                            {
                                lValue = lHeaderLine.Substring(lPos + 1);
                            }
                        }

                        HttpHeader lHeader = this[lName];
                        if (lHeader == null)
                        {
                            lHeader = new HttpHeader(lName, lValue);
                            fHeaders.Add(lName, lHeader);
                        }
                        else
                        {
                            lHeader.Add(lValue);
                        }
                    }
                }

                if (this.MaxHeaderLinesEnabled && this.fHeaders.Count > this.MaxHeaderLines - 1)                 // -1 because FirstHeader is not in hashtable
                {
                    connection.Disconnect();
                    throw new HttpHeaderException(String.Format("Too many header lines received (maximum is set to {0})", MaxHeaderLines));
                }
            }while (!String.IsNullOrEmpty(lHeaderLine));

            this.ParseFirstLine();

            return(true);
        }