Skip to content
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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vyskocilm
Copy link
Contributor

  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.

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.
local next = function(_, _)
local key, value
repeat
_, key, value = coroutine.resume(co)
Copy link
Contributor Author

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.

@gorillamoe
Copy link
Member

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.

@gorillamoe gorillamoe added the enhancement New feature or request label Oct 19, 2024
 * 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
@vyskocilm
Copy link
Contributor Author

@gorillamoe please check the latest change - table have two methods has and has_exact. Both can name or name/value pair.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants