Allow lists to be embedded in query strings

mysql-performance
Melanie 2009-12-27 21:46:16 +00:00
parent cbe434149e
commit be41ba6670
1 changed files with 54 additions and 11 deletions

View File

@ -180,7 +180,31 @@ namespace OpenSim.Server.Base
if (elems.Length > 1) if (elems.Length > 1)
value = System.Web.HttpUtility.UrlDecode(elems[1]); value = System.Web.HttpUtility.UrlDecode(elems[1]);
result[name] = value; if (name.EndsWith("[]"))
{
if (result.ContainsKey(name))
{
if (!(result[name] is List<string>))
continue;
List<string> l = (List<string>)result[name];
l.Add(value);
}
else
{
List<string> newList = new List<string>();
newList.Add(value);
result[name] = newList;
}
}
else
{
if (!result.ContainsKey(name))
result[name] = value;
}
} }
return result; return result;
@ -190,23 +214,42 @@ namespace OpenSim.Server.Base
{ {
string qstring = String.Empty; string qstring = String.Empty;
string part;
foreach (KeyValuePair<string, object> kvp in data) foreach (KeyValuePair<string, object> kvp in data)
{ {
string part; if (kvp.Value is List<string>)
if (kvp.Value.ToString() != String.Empty)
{ {
part = System.Web.HttpUtility.UrlEncode(kvp.Key) + List<string> l = (List<String>)kvp.Value;
"=" + System.Web.HttpUtility.UrlEncode(kvp.Value.ToString());
foreach (string s in l)
{
part = System.Web.HttpUtility.UrlEncode(kvp.Key) +
"[]=" + System.Web.HttpUtility.UrlEncode(s);
if (qstring != String.Empty)
qstring += "&";
qstring += part;
}
} }
else else
{ {
part = System.Web.HttpUtility.UrlEncode(kvp.Key); if (kvp.Value.ToString() != String.Empty)
{
part = System.Web.HttpUtility.UrlEncode(kvp.Key) +
"=" + System.Web.HttpUtility.UrlEncode(kvp.Value.ToString());
}
else
{
part = System.Web.HttpUtility.UrlEncode(kvp.Key);
}
if (qstring != String.Empty)
qstring += "&";
qstring += part;
} }
if (qstring != String.Empty)
qstring += "&";
qstring += part;
} }
return qstring; return qstring;