Esempio n. 1
0
        /// <summary>Creates a deep copy of the HttpInput class</summary>
        /// <param name="input">The object to copy</param>
        /// <remarks>The function makes a deep copy of quite a lot which can be slow</remarks>
        protected HttpInput(HttpInput input)
        {
            foreach (HttpInputItem item in input)
            {
                _items.Add(item.Name, new HttpInputItem(item));
            }

            Name           = input._name;
            _ignoreChanges = input._ignoreChanges;
        }
        /// <summary>
        /// Add a sub item.
        /// </summary>
        /// <param name="name">Can contain array formatting, the item is then parsed and added in multiple levels</param>
        /// <param name="value">Value to add.</param>
        /// <exception cref="ArgumentNullException">Argument is null.</exception>
        /// <exception cref="InvalidOperationException">Cannot add stuff to <see cref="HttpInput.Empty"/>.</exception>
        public void Add(string name, string value)
        {
            if (name == null && value != null)
            {
                throw new ArgumentNullException("name");
            }
            if (name == null)
            {
                return;
            }
            if (_ignoreChanges)
            {
                throw new InvalidOperationException("Cannot add stuff to HttpInput.Empty.");
            }

            int pos = name.IndexOf('[');

            if (pos != -1)
            {
                string name1 = name.Substring(0, pos);
                string name2 = HttpInput.ExtractOne(name);
                if (!_items.ContainsKey(name1))
                {
                    _items.Add(name1, new HttpInputItem(name1, null));
                }
                _items[name1].Add(name2, value);

                /*
                 * HttpInputItem item = HttpInput.ParseItem(name, value);
                 *
                 * // Add the value to an existing sub item
                 * if (_items.ContainsKey(item.Name))
                 *  _items[item.Name].Add(item.Value);
                 * else
                 *  _items.Add(item.Name, item);
                 */
            }
            else
            {
                if (_items.ContainsKey(name))
                {
                    _items[name].Add(value);
                }
                else
                {
                    _items.Add(name, new HttpInputItem(name, value));
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Clear everything in the request
        /// </summary>
        public void Clear()
        {
            _body.Dispose();
            _body          = new MemoryStream();
            _contentLength = 0;
            _method        = string.Empty;
            _uri           = null;
            _queryString   = HttpInput.Empty;
            _bodyBytesLeft = 0;
            _headers.Clear();
            _connection = ConnectionType.Close;
            _param.SetForm(HttpInput.Empty);
            _param.SetQueryString(HttpInput.Empty);
            _form.Clear();

            AcceptTypes = null;
            Cookies     = null;
            IsAjax      = false;
            UriParts    = null;
        }
Esempio n. 4
0
        /// <summary>
        /// Parses a query string.
        /// </summary>
        /// <param name="queryString">Query string (URI encoded)</param>
        /// <param name="contentEncoding">Content encoding</param>
        /// <returns>A <see cref="HttpInput"/> object if successful; otherwise <see cref="HttpInput.Empty"/></returns>
        /// <exception cref="ArgumentNullException"><c>queryString</c> is <c>null</c>.</exception>
        /// <exception cref="FormatException">If string cannot be parsed.</exception>
        public static HttpInput ParseQueryString(string queryString, Encoding contentEncoding)
        {
            if (queryString == null)
            {
                throw new ArgumentNullException("queryString");
            }
            if (queryString == string.Empty)
            {
                return(HttpInput.Empty);
            }

            HttpInput input = new HttpInput("QueryString");

            queryString = queryString.TrimStart('?', '&');

            // a simple value.

            /*
             * if (queryString.IndexOf("&") == -1 && !queryString.Contains("%3d") && !queryString.Contains("%3D") && !queryString.Contains("="))
             * {
             *      input.Add(string.Empty, queryString);
             *      return input;
             * }*/
            if (queryString.IndexOf("&") == -1 && !queryString.Contains("="))
            {
                input.Add(string.Empty, queryString);
                return(input);
            }

            int    state    = 0;
            int    startpos = 0;
            string name     = null;

            for (int i = 0; i < queryString.Length; ++i)
            {
                int newIndexPos;
                if (state == 0 && IsEqual(queryString, ref i, out newIndexPos))
                {
                    name     = queryString.Substring(startpos, i - startpos);
                    i        = newIndexPos;
                    startpos = i + 1;
                    ++state;
                }
                else if (state == 1 && IsAmp(queryString, ref i, out newIndexPos))
                {
                    Add(input, name, queryString.Substring(startpos, i - startpos), contentEncoding);
                    i        = newIndexPos;
                    startpos = i + 1;
                    state    = 0;
                    name     = null;
                }
            }

            if (state == 0 && !input.GetEnumerator().MoveNext())
            {
                throw new FormatException("Not a valid query string: " + queryString);
            }

            if (startpos <= queryString.Length)
            {
                if (name != null)
                {
                    Add(input, name, queryString.Substring(startpos, queryString.Length - startpos), contentEncoding);
                }
                else
                {
                    Add(input, string.Empty, queryString.Substring(startpos, queryString.Length - startpos), contentEncoding);
                }
            }


            return(input);
        }
Esempio n. 5
0
 /// <summary>
 /// Makes a deep copy of the input
 /// </summary>
 /// <param name="input">The input to copy</param>
 public HttpForm(HttpInput input) : base(input)
 {
 }
Esempio n. 6
0
 internal void SetForm(HttpInput form)
 {
     _form = form;
 }
Esempio n. 7
0
 internal void SetQueryString(HttpInput query)
 {
     _query = query;
 }