예제 #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;
        }
예제 #2
0
		/// <summary>
		/// Initializes a new instance of the HttpMessage class
		/// </summary>
		/// <param name="message"></param>
		public HttpMessage(HttpMessage message)
		{
			_firstLine = message.FirstLine;
			_headers = new HttpHeaderList();
			foreach(HttpHeader header in message.Headers)
				_headers.Add(new HttpHeader(header.Name, header.Value));
			this.Body = message.Body;
		}
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the HttpMessage class
 /// </summary>
 /// <param name="message"></param>
 public HttpMessage(HttpMessage message)
 {
     _firstLine = message.FirstLine;
     _headers   = new HttpHeaderList();
     foreach (HttpHeader header in message.Headers)
     {
         _headers.Add(new HttpHeader(header.Name, header.Value));
     }
     this.Body = message.Body;
 }