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

Add header flag parser and passthru for introspection #351

Merged
merged 1 commit into from
Mar 23, 2021

Conversation

JakeDawkins
Copy link
Contributor

These changes are fairly small, but add the ability to pass through headers, similarly to how curl works with --header or -H.

Valid examples:

# single headers
rover graph introspect http://localhost:4000 --header auth:hello
rover graph introspect http://localhost:4000 -H auth:hello
rover graph introspect http://localhost:4000 -H "auth:hello"
rover graph introspect http://localhost:4000 --header auth:"hello"
rover graph introspect http://localhost:4000 --header "auth:value with spaces"
rover graph introspect http://localhost:4000 --header auth:"value with spaces"

# I think reqwest is stripping leading whitespace from header values automatically (which is what we'd want), 
# even though with the current implementation, leading whitespaces are added to the header map
rover graph introspect http://localhost:4000 --header "auth: value with leading spaces"

# multiple headers
rover graph introspect http://localhost:4000 --header auth:hello another:header
rover graph introspect http://localhost:4000 --header auth:hello --header another:header
rover graph introspect http://localhost:4000 --header auth:hello -H another:header
rover graph introspect http://localhost:4000 --header auth:hello -H "another-header:with spaces"

/// Parses a key:value pair from a string and returns a tuple of key:value.
/// If a full key:value can't be parsed, it will error.
pub fn parse_header(header: &str) -> Result<(String, String)> {
// only split once, a header's value may have a ":" in it, but not a key. Right?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if it has a :, it'll likely be in a quoted string. The only : that's likely to be there is the one that separates the header key and the header value. The values are just going to be comma separated. That is to say the parsing you have below seems correct to me.

From the spec:

message-header = field-name ":" [ field-value ]
field-name     = token
field-value    = *( field-content | LWS )
field-content  = <the OCTETs making up the field-value
                 and consisting of either *TEXT or combinations
                 of token, separators, and quoted-string>

@lrlna lrlna merged commit 85e7c85 into build_schema Mar 23, 2021
@lrlna lrlna deleted the jake/introspection-headers branch March 23, 2021 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants