Exemple #1
0
        /// <summary>
        /// Completes the parsing of the request.
        /// </summary>
        public void EndParse()
        {
            string host;
            int    pos;

            if (parseState != ParseState.GotAll)
            {
                throw new InvalidOperationException(BadParseMsg);
            }

            content       = contentParser.EndParse();
            contentParser = null;
            parseState    = ParseState.Done;

            // Build up the request URI.

            host = base["Host"];
            if (host == null)
            {
                host = "localhost";
            }

            pos = host.IndexOf(':');    // Strip off the port if present
            if (pos != -1)
            {
                host = host.Substring(0, pos);
            }

            uri = new Uri(new Uri(string.Format("http://{0}:{1}", host, parsePort)), base.RawUri);
        }
Exemple #2
0
 /// <summary>
 /// Constructs a response to be parsed from a network stream.
 /// </summary>
 /// <param name="cbContentMax">Maximum allowed content size or <b>-1</b> to disable checking.</param>
 public HttpResponse(int cbContentMax)
     : base(false)
 {
     this.parseState    = ParseState.None;
     this.contentParser = null;
     this.content       = null;
     this.cbContentMax  = cbContentMax;
 }
Exemple #3
0
 /// <summary>
 /// Constructs a request to be parsed from a network stream.
 /// </summary>
 /// <param name="cbContentMax">Maximum allowed content size or <b>-1</b> to disable checking.</param>
 public HttpRequest(int cbContentMax)
     : base(true)
 {
     this.parseState    = ParseState.None;
     this.contentParser = null;
     this.content       = null;
     this.cbContentMax  = cbContentMax;
 }
Exemple #4
0
        /// <summary>
        /// Completes the parsing of the response.
        /// </summary>
        public void EndParse()
        {
            if (parseState != ParseState.GotAll)
            {
                throw new InvalidOperationException(BadParseMsg);
            }

            content       = contentParser.EndParse();
            contentParser = null;
            parseState    = ParseState.Done;
        }
Exemple #5
0
        /// <summary>
        /// Handles the parsing of received data.
        /// </summary>
        /// <param name="data">The received data.</param>
        /// <param name="cb">Number of bytes received.</param>
        /// <returns><c>true</c> if the data has been completely parsed.</returns>
        /// <remarks>
        /// <note>
        /// The data buffer passed MUST NOT be reused.  Ownership
        /// will be taken over by this instance.
        /// </note>
        /// </remarks>
        /// <exception cref="HttpBadProtocolException">Badly formatted HTTP message.</exception>
        public new bool Parse(byte[] data, int cb)
        {
            switch (parseState)
            {
            case ParseState.Headers:

                BlockArray blocks;
                int        dataPos;

                if (base.Parse(data, cb))
                {
                    blocks        = base.EndParse(out dataPos);
                    parseState    = ParseState.Content;
                    contentParser = new HttpContentParser(this, cbContentMax);

                    if (contentParser.BeginParse(blocks, dataPos))
                    {
                        parseState = ParseState.GotAll;
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }

                break;

            case ParseState.Content:

                if (contentParser.Parse(data, cb))
                {
                    parseState = ParseState.GotAll;
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:

                throw new InvalidOperationException(BadParseMsg);
            }

            return(false);
        }