Add case-insensitive table lookups, and use for host and content-type.#236
Merged
NTBBloodbath merged 1 commit intorest-nvim:mainfrom Oct 10, 2023
PhilRunninger:case-insensitive-headers
Merged
Add case-insensitive table lookups, and use for host and content-type.#236NTBBloodbath merged 1 commit intorest-nvim:mainfrom PhilRunninger:case-insensitive-headers
NTBBloodbath merged 1 commit intorest-nvim:mainfrom
PhilRunninger:case-insensitive-headers
Conversation
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.
|
@teto can we please get this merged? I struggled a lot with this case sensitivity. |
NTBBloodbath
approved these changes
Oct 10, 2023
Member
NTBBloodbath
left a comment
There was a problem hiding this comment.
LGTM! Sorry for the delay, life is a little busy and I can't fully focus on every project I have yet!
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #163.
A new utility function called
keytakes 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: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.