private string ParseNameValues(NameValueCollection cc, StringCollection sc, int start)
{
WebHeaderCollection wc = cc as WebHeaderCollection;
string lastHeaderName = null;
if (sc != null)
{
for (int i = start; i < sc.Count; ++i)
{
string s = sc[i];
if (s == null || s.Length == 0)
{
//An empty string stands for \r\n
//Treat that as the end of headers and ignore the rest
return null;
}
if (s[0] == ' ' || s[0] == '\t')
{
if (lastHeaderName == null) {return s;}
if (wc != null)
wc.AddInternal(lastHeaderName, s);
else
cc.Add(lastHeaderName, s);
}
int colpos = s.IndexOf(':');
if (colpos < 0)
{return s;}
lastHeaderName = s.Substring(0, colpos);
while (++colpos < s.Length && (s[colpos] == ' ' || s[colpos] == '\t'))
{;}
try {
if (wc != null)
wc.AddInternal(lastHeaderName, s.Substring(colpos));
else
cc.Add(lastHeaderName, s.Substring(colpos));
}
catch(Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
throw;
// Otherwise the value of 's' will be used to log an error.
// The fact that we cannot parse headers may stand for corrupted metadata that we try to ignore
return s;
}
}
}
return null;
}
//