-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add case-insensitive table lookups, and use for host and content-type. (
#236) A new utility function called `key` takes a table and a key. It loops through the table items, comparing the each key with the given search key in a case-insensitive manner. Return the first matching key; otherwise, return the given search key. This allows operations like these to be performed: ```lua local t = {s=37, S=73} t[utils.key(t,'a')] = 1 -- Insert a:1 t == {s=37,S=73,a=1} y = t[utils.key(t,'a')] -- Find 'a' y == 1 z = t[utils.key(t,'A')] -- Find 'A' (same as 'a') z == 1 m = t[utils.key(t,'b')] -- Show 'b' is missing. m == nil k = utils.key(t,'s') -- Which 's/S' is first? k is indeterminate l = t['s'] -- Get 's' and 'S' l = 37 u = t['S'] -- in the usual manner. u = 73 t[utils.key(t,'a')] = nil -- Delete 'a' t == {s=37, S=73} ``` As implied by the `k = ` example above, lua associative tables are unordered, so there's no guarantee that 's' (or 'S') is the first one to be found. In this context, that shouldn't be too much of an issue. Use this new function to find the 'Host' and 'Content-Type' headers' values no matter in what case they were defined.
- Loading branch information
1 parent
8b62563
commit 5bcaa10
Showing
6 changed files
with
23 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
### | ||
|
||
GET /api/users?page=5 | ||
Host: https://reqres.in | ||
host: https://reqres.in | ||
|
||
### | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters