/// <summary>Actually formats a request line.</summary>
        /// <remarks>
        /// Actually formats a request line.
        /// Called from
        /// <see cref="FormatRequestLine(Org.Apache.Http.RequestLine, LineFormatter)">FormatRequestLine(Org.Apache.Http.RequestLine, LineFormatter)
        ///     </see>
        /// .
        /// </remarks>
        /// <param name="buffer">
        /// the empty buffer into which to format,
        /// never <code>null</code>
        /// </param>
        /// <param name="reqline">the request line to format, never <code>null</code></param>
        protected internal virtual void DoFormatRequestLine(CharArrayBuffer buffer, RequestLine
                                                            reqline)
        {
            string method = reqline.GetMethod();
            string uri    = reqline.GetUri();
            // room for "GET /index.html HTTP/1.1"
            int len = method.Length + 1 + uri.Length + 1 + EstimateProtocolVersionLen(reqline
                                                                                      .GetProtocolVersion());

            buffer.EnsureCapacity(len);
            buffer.Append(method);
            buffer.Append(' ');
            buffer.Append(uri);
            buffer.Append(' ');
            AppendProtocolVersion(buffer, reqline.GetProtocolVersion());
        }
        // formatHeader
        /// <summary>Actually formats a header.</summary>
        /// <remarks>
        /// Actually formats a header.
        /// Called from
        /// <see cref="FormatHeader(Org.Apache.Http.Header, LineFormatter)">FormatHeader(Org.Apache.Http.Header, LineFormatter)
        ///     </see>
        /// .
        /// </remarks>
        /// <param name="buffer">
        /// the empty buffer into which to format,
        /// never <code>null</code>
        /// </param>
        /// <param name="header">the header to format, never <code>null</code></param>
        protected internal virtual void DoFormatHeader(CharArrayBuffer buffer, Header header
                                                       )
        {
            string name  = header.GetName();
            string value = header.GetValue();
            int    len   = name.Length + 2;

            if (value != null)
            {
                len += value.Length;
            }
            buffer.EnsureCapacity(len);
            buffer.Append(name);
            buffer.Append(": ");
            if (value != null)
            {
                buffer.Append(value);
            }
        }
        /// <summary>Actually formats a status line.</summary>
        /// <remarks>
        /// Actually formats a status line.
        /// Called from
        /// <see cref="FormatStatusLine(Org.Apache.Http.StatusLine, LineFormatter)">FormatStatusLine(Org.Apache.Http.StatusLine, LineFormatter)
        ///     </see>
        /// .
        /// </remarks>
        /// <param name="buffer">
        /// the empty buffer into which to format,
        /// never <code>null</code>
        /// </param>
        /// <param name="statline">the status line to format, never <code>null</code></param>
        protected internal virtual void DoFormatStatusLine(CharArrayBuffer buffer, StatusLine
                                                           statline)
        {
            int len = EstimateProtocolVersionLen(statline.GetProtocolVersion()) + 1 + 3 + 1;
            // room for "HTTP/1.1 200 "
            string reason = statline.GetReasonPhrase();

            if (reason != null)
            {
                len += reason.Length;
            }
            buffer.EnsureCapacity(len);
            AppendProtocolVersion(buffer, statline.GetProtocolVersion());
            buffer.Append(' ');
            buffer.Append(Sharpen.Extensions.ToString(statline.GetStatusCode()));
            buffer.Append(' ');
            // keep whitespace even if reason phrase is empty
            if (reason != null)
            {
                buffer.Append(reason);
            }
        }