Beispiel #1
0
        /// <summary>Creates a new header from a buffer.</summary>
        /// <remarks>
        /// Creates a new header from a buffer.
        /// The name of the header will be parsed immediately,
        /// the value only if it is accessed.
        /// </remarks>
        /// <param name="buffer">the buffer containing the header to represent</param>
        /// <exception cref="Org.Apache.Http.ParseException">in case of a parse error</exception>
        public BufferedHeader(CharArrayBuffer buffer) : base()
        {
            Args.NotNull(buffer, "Char array buffer");
            int colon = buffer.IndexOf(':');

            if (colon == -1)
            {
                throw new ParseException("Invalid header: " + buffer.ToString());
            }
            string s = buffer.SubstringTrimmed(0, colon);

            if (s.Length == 0)
            {
                throw new ParseException("Invalid header: " + buffer.ToString());
            }
            this.buffer   = buffer;
            this.name     = s;
            this.valuePos = colon + 1;
        }
        /// <exception cref="System.IO.IOException"></exception>
        public virtual string ReadLine()
        {
            CharArrayBuffer charbuffer = new CharArrayBuffer(64);
            int             l          = ReadLine(charbuffer);

            if (l != -1)
            {
                return(charbuffer.ToString());
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Generates textual representation of this content type which can be used as the value
        /// of a <code>Content-Type</code> header.
        /// </summary>
        /// <remarks>
        /// Generates textual representation of this content type which can be used as the value
        /// of a <code>Content-Type</code> header.
        /// </remarks>
        public override string ToString()
        {
            CharArrayBuffer buf = new CharArrayBuffer(64);

            buf.Append(this.mimeType);
            if (this.@params != null)
            {
                buf.Append("; ");
                BasicHeaderValueFormatter.Instance.FormatParameters(buf, this.@params, false);
            }
            else
            {
                if (this.charset != null)
                {
                    buf.Append("; charset=");
                    buf.Append(this.charset.Name());
                }
            }
            return(buf.ToString());
        }
 /// <summary>Gets a header representing all of the header values with the given name.
 ///     </summary>
 /// <remarks>
 /// Gets a header representing all of the header values with the given name.
 /// If more that one header with the given name exists the values will be
 /// combined with a "," as per RFC 2616.
 /// <p>Header name comparison is case insensitive.
 /// </remarks>
 /// <param name="name">the name of the header(s) to get</param>
 /// <returns>
 /// a header with a condensed value or <code>null</code> if no
 /// headers by the given name are present
 /// </returns>
 public virtual Header GetCondensedHeader(string name)
 {
     Header[] hdrs = GetHeaders(name);
     if (hdrs.Length == 0)
     {
         return(null);
     }
     else
     {
         if (hdrs.Length == 1)
         {
             return(hdrs[0]);
         }
         else
         {
             CharArrayBuffer valueBuffer = new CharArrayBuffer(128);
             valueBuffer.Append(hdrs[0].GetValue());
             for (int i = 1; i < hdrs.Length; i++)
             {
                 valueBuffer.Append(", ");
                 valueBuffer.Append(hdrs[i].GetValue());
             }
             return(new BasicHeader(name.ToLower(Sharpen.Extensions.GetEnglishCulture()), valueBuffer
                                    .ToString()));
         }
     }
 }