Example #1
0
 /// <summary>
 ///     Extract Request cookies from the header.
 ///     <para>Cookies are case-sensitive in most scenarios.</para>
 ///     <para>
 ///         But since the RFC standard doesn't enforce it, the <paramref name="isCaseSensitive" /> can be used to change
 ///         behaviour.
 ///     </para>
 /// </summary>
 /// <param name="headers"></param>
 /// <param name="isCaseSensitive"></param>
 /// <returns></returns>
 internal static IDictionary<string, string> ParseRequestCookies(ILiaraHashTable<string> headers,
     bool isCaseSensitive = true)
 {
     var cookies = new Dictionary<string, string>(isCaseSensitive
         ? StringComparer.Ordinal
         : StringComparer.OrdinalIgnoreCase);
     string text = headers.Get(Constants.RequestHeaderConstants.Cookie);
     StringHelpers.ParseUrlEncodedString(text, SemicolonAndComma, AddCookieCallback, cookies);
     return cookies;
 }
Example #2
0
        /// <summary>
        ///     Extract Request cookies from the header.
        ///     <para>Cookies are case-sensitive in most scenarios.</para>
        ///     <para>
        ///         But since the RFC standard doesn't enforce it, the <paramref name="isCaseSensitive" /> can be used to change
        ///         behaviour.
        ///     </para>
        /// </summary>
        /// <param name="headers"></param>
        /// <param name="isCaseSensitive"></param>
        /// <returns></returns>
        internal static IDictionary <string, string> ParseRequestCookies(ILiaraHashTable <string> headers,
                                                                         bool isCaseSensitive = true)
        {
            var cookies = new Dictionary <string, string>(isCaseSensitive
                ? StringComparer.Ordinal
                : StringComparer.OrdinalIgnoreCase);
            string text = headers.Get(Constants.RequestHeaderConstants.Cookie);

            StringHelpers.ParseUrlEncodedString(text, SemicolonAndComma, AddCookieCallback, cookies);
            return(cookies);
        }
Example #3
0
        /// <summary>
        ///     Return the correctly formed and escaped query string that is can directly be added
        ///     to the Uri component, including the leading "?".
        /// </summary>
        /// <returns>Correct query string, with the leading "?"</returns>
        public static string ConvertToUriString(ILiaraHashTable <string> queryString, char seperator = '&',
                                                bool prefixQuestionMark = true)
        {
            if (queryString.Count < 1)
            {
                return(null);
            }
            string ampChar = null;

            if (prefixQuestionMark)
            {
                ampChar = "?";
            }

            var sb = new StringBuilder(ampChar);

            var shouldAddAmpersand = false;

            foreach (KeyValuePair <string, string[]> kvp in queryString)
            {
                foreach (var itemValue in kvp.Value)
                {
                    if (shouldAddAmpersand)
                    {
                        sb.Append(seperator);
                    }
                    else
                    {
                        shouldAddAmpersand = true;
                    }

                    if (itemValue == null)
                    {
                        // Query parameter without value. Don't add '=' symbol.
                        sb.Append(Uri.EscapeDataString(kvp.Key));
                    }
                    else
                    {
                        sb.Append(string.Concat(
                                      Uri.EscapeDataString(kvp.Key),
                                      "=",
                                      Uri.EscapeDataString(itemValue)));
                    }
                }
            }

            return(sb.ToString());
        }
Example #4
0
        /// <summary>
        ///     Return the correctly formed and escaped query string that is can directly be added
        ///     to the Uri component, including the leading "?".
        /// </summary>
        /// <returns>Correct query string, with the leading "?"</returns>
        public static string ConvertToUriString(ILiaraHashTable<string> queryString, char seperator = '&',
            bool prefixQuestionMark = true)
        {
            if (queryString.Count < 1)
            {
                return null;
            }
            string ampChar = null;
            if (prefixQuestionMark)
            {
                ampChar = "?";
            }

            var sb = new StringBuilder(ampChar);

            var shouldAddAmpersand = false;
            foreach (KeyValuePair<string, string[]> kvp in queryString)
            {
                foreach (var itemValue in kvp.Value)
                {
                    if (shouldAddAmpersand)
                    {
                        sb.Append(seperator);
                    }
                    else
                    {
                        shouldAddAmpersand = true;
                    }

                    if (itemValue == null)
                    {
                        // Query parameter without value. Don't add '=' symbol.
                        sb.Append(Uri.EscapeDataString(kvp.Key));
                    }
                    else
                    {
                        sb.Append(string.Concat(
                            Uri.EscapeDataString(kvp.Key),
                            "=",
                            Uri.EscapeDataString(itemValue)));
                    }
                }
            }

            return sb.ToString();
        }
Example #5
0
 public LiaraHeaderEntry(ILiaraHashTable <string> headers, string headerName)
 {
     this.headers = headers;
     fieldName    = headerName;
 }
Example #6
0
 public LiaraHeaderEntry(ILiaraHashTable<string> headers, string headerName)
 {
     this.headers = headers;
     fieldName = headerName;
 }