Commit 5bcaa10
authored
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.1 parent 8b62563 commit 5bcaa10
6 files changed
Lines changed: 23 additions & 22 deletions
File tree
- lua/rest-nvim
- curl
- request
- utils
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
114 | 109 | | |
115 | 110 | | |
116 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 104 | + | |
111 | 105 | | |
112 | 106 | | |
113 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
295 | 292 | | |
296 | 293 | | |
297 | 294 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| |||
286 | 287 | | |
287 | 288 | | |
288 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
289 | 303 | | |
290 | 304 | | |
291 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
0 commit comments