Exemplo n.º 1
0
        /// <summary>
        /// Write the value to the specified header, optionally deletes the header if the value is empty or null
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="deleteIfEmptyOrNull"></param>
        public virtual void WriteHeaderValue(string name, string value, bool deleteIfNullOrEmpty)
        {
            if (deleteIfNullOrEmpty)
            {
                if (HttpUtils.IsEmptryString(value) || HttpUtils.IsNullString(value))
                {
                    _headers.Remove(name);
                    return;
                }
            }

            // validate the header value, not empty, null, or contains CR or LF
            HttpUtils.ValidateToken(name, value);

            // otherwise if it doesn't exist
            if (!_headers.Contains(name))
            {
                // add it in with the value specified
                _headers.Add(new HttpHeader(name, value));
                return;
            }

            // or finally just update the one that exists
            _headers[name].Value = value;
        }