/// <summary> /// Returns the values for the specified header name. /// </summary> /// <param name="header">The name of the header.</param> /// <returns>An array of parsed string objects.</returns> /// <remarks> /// Takes a header name and returns a string array representing /// the individual values for that header. For example, if the headers /// contain the following line: /// <code> /// Accept: text/plain, text/html /// </code> /// then <c>GetValues("Accept")</c> returns an array of /// two strings: "text/plain" and "text/html". /// </remarks> public string[] GetValues(string header) { // Get the value pair for the header. HeaderInfo Info = HInfo[header]; HeaderValuePair pair = head_val_coll.GetValuePair(header); // If header not present or value string not present or empty - // return null. if (pair == null || pair.value == null || pair.value.Length == 0) { return(null); } // Header present. Parse the value string. There is non-empty value // string. if (Info == null || !Info.AllowMultiValues) { string[] retVal = new string[1]; retVal[0] = pair.value; return(retVal); } // Multivalue header return(Info.Parser(pair.value)); }
/// <summary> /// Adds a header and a value for the header into the collection. /// </summary> /// <param name="header">String for header</param> /// <param name="value">String for value</param> /// <remarks> /// If the specified header is already present, the value is appended to /// that header. /// </remarks> public void Add(string header, string value) { // Checks is we already have the header. HeaderValuePair pair = GetValuePair(header); // If found, adds valus to existing valies. if (pair != null) { pair.value += "," + value; } else // if not found - then we add it. { base.Add(new HeaderValuePair(header, value)); } }
/// <summary> /// Returns the string value for the header. /// </summary> /// <param name="header">The name of the header.</param> /// <value>A string containing the value. If no value is present, /// returns <itemref>null</itemref>.</value> public string this[string header] { get { HeaderValuePair pair = head_val_coll.GetValuePair(header); // If header is not present, then pair is null. Return null // string if (pair == null) { return(null); } // Pair was found. Return the value string of it return(pair.value); } }