0

Is it possible? I'm building a REST Api with vibe.d and implementing token authentication. Because I'm not aware in which casing the user will send me Authorization header parameter, I need to query it in case insensitive manner. For example:

string[string] foo;
foo["XXX"] = "YYY";
logInfo(*("xxx" in foo)); // BOOM. Exception here

Is it possible..?

Thanks

Davita
  • 8,928
  • 14
  • 67
  • 119

2 Answers2

2

Simply lowercase all keys of the associative array before you store or query them.

cfh
  • 4,576
  • 1
  • 24
  • 34
  • Thanks. I hoped there could be a more efficient solution. iterating on all keys and lowercasing them on every HTTP request seems like an overkill solution... – Davita May 04 '15 at 14:18
  • @Davita: What do you mean, on all keys? If you already built the array with only lowercase keys, then you only need to lowercase the "xxx" in your example. – cfh May 04 '15 at 14:19
  • I don't build the keys. The array is given to me by vibe.d framework. It contains http headers passed by client. I don't control casing here :) – Davita May 04 '15 at 14:24
  • @Davita Then perhaps you should contact the vibe.d folks about an enhancement where it makes all of the keys lowercase for you. But the AA itself is always going to use `toHash` and `==` for key comparisons, and that's not case insensitive for `string`. – Jonathan M Davis May 04 '15 at 15:26
1

if the case is either all lower or all upper, then you might have something like

"xxx" in foo && logInfo(foo["xxx"]);
"XXX" in foo && logInfo(foo["XXX"]);

maybe there's more efficient way to do this. If you don't have control over how the keys are entered in the AA, then it seems you have to check all casing variants when querying a specific key.

dmakarov
  • 81
  • 4