-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(parser): add a HTTPHeaders table tuned to a work with HTTP headers #287
base: main
Are you sure you want to change the base?
Conversation
1. it's used as regular lua table h[name] or h[name] = value works 2. names are case-insensitive 3. values can be "flattened", so a name, single-value is returned. This is handly for curl command line generation.
lua/kulala/parser/headers.lua
Outdated
local next = function(_, _) | ||
local key, value | ||
repeat | ||
_, key, value = coroutine.resume(co) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly I haven't found easier way how to flatten the string => []string
to string => string
than using coroutines. I really did not want to manage the state when traversing the _headers
table and this is where coroutines helps.
I think this looks really good, with a small nitpick. I need to have a way to check for the existance of a specific header with a specific value, but want to have both header name and header value treated case insensitive, e.g. so I can check for this: headers.has("x-request-type", "graphql", case_sensitive) So param 2 and 3 could be potentially nil in any combination, where I can also have something like this headers.has("X-REQUEST-TYPE", nil, true) Where it would look for an all uppercase header and does not care about its value. I don't think we have a use-case for having a strict case sensitive check as of now, so you might want to skip that part, but I need a way to check for these headers with values. |
* has have an optional parameter value, if not nil, then name/value pair is searched, case insensitive * has_exact does a case_sensitive search of name and value
@gorillamoe please check the latest change - table have two methods |
is handly for curl command line generation.