Пример #1
0
 /// <summary>
 /// Parses the HTTP request out of the given <paramref name="stream"/>.
 /// </summary>
 /// <param name="stream">HTTP data stream to parse.</param>
 /// <param name="result">Returns the parsed HTTP request instance.</param>
 /// <exception cref="MediaPortal.Utilities.Exceptions.InvalidDataException">If the given <paramref name="stream"/> is malformed.</exception>
 public static void Parse(Stream stream, out SimpleHTTPRequest result)
 {
   result = new SimpleHTTPRequest();
   string firstLine;
   result.ParseHeaderAndBody(stream, out firstLine);
   string[] elements = firstLine.Split(' ');
   if (elements.Length != 3)
     throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
   string httpVersion = elements[2];
   if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1")
     throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
   result._method = elements[0];
   result._param = elements[1];
   result._httpVersion = httpVersion;
 }
Пример #2
0
        /// <summary>
        /// Parses the HTTP request out of the given <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">HTTP data stream to parse.</param>
        /// <param name="result">Returns the parsed HTTP request instance.</param>
        /// <exception cref="MediaPortal.Utilities.Exceptions.InvalidDataException">If the given <paramref name="stream"/> is malformed.</exception>
        public static void Parse(Stream stream, out SimpleHTTPRequest result)
        {
            result = new SimpleHTTPRequest();
            string firstLine;

            result.ParseHeaderAndBody(stream, out firstLine);
            string[] elements = firstLine.Split(' ');
            if (elements.Length != 3)
            {
                throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
            }
            string httpVersion = elements[2];

            if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1")
            {
                throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
            }
            result._method      = elements[0];
            result._param       = elements[1];
            result._httpVersion = httpVersion;
        }