static bool AppendResult(
            string line,
            ref string currentRequestLine,
            HttpHeaderEntries currentEntries)
        {
            string key, value;

            // We found a blank line! Header ends here.
            if (string.IsNullOrWhiteSpace(line))
            {
                return(false);
            }
            // We found a request line
            else if (currentRequestLine == null)
            {
                currentRequestLine = line;
            }
            // We found a header key:value line
            else
            {
                HttpHeaderLineParser.Parse(line, out key, out value);
                currentEntries.Add(key, value);
            }

            return(true);
        }
Exemple #2
0
 protected HttpHeader(
     string startLine          = null,
     HttpHeaderEntries entries = null)
 {
     _startLine = startLine ?? String.Empty;
     if (entries != null)
     {
         _entries.CopyEntries(from: entries);
     }
 }
Exemple #3
0
        public static void CopyEntries(this HttpHeaderEntries to, HttpHeaderEntries from)
        {
            if (to == null)
            {
                throw new ArgumentNullException(nameof(to));
            }
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }

            foreach (var key in from.Keys)
            {
                var values = from.Get(key, false);
                for (int i = 0; i < values.Count; i++)
                {
                    string value = values[i];
                    to.Add(key, value);
                }
            }
        }
Exemple #4
0
        public static string GeneratePlainHeader(
            this HttpHeaderEntries entries,
            string startLine)
        {
            var headerBuilder = new StringBuilder();

            headerBuilder.Append(startLine);
            headerBuilder.Append(SpecialChars.CRNL);

            foreach (var key in entries.Keys)
            {
                foreach (var value in entries.Get(key, false))
                {
                    headerBuilder.Append(String.Format("{0}: {1}", key, value));
                    headerBuilder.Append(SpecialChars.CRNL);
                }
            }

            headerBuilder.Append(SpecialChars.CRNL);

            return(headerBuilder.ToString());
        }