-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(cli): add --http-header option #3638
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,13 +45,14 @@ var ( | |
|
|
||
| // CommonOptions are options common to both the client and the daemon. | ||
| type CommonOptions struct { | ||
| Debug bool | ||
| Hosts []string | ||
| LogLevel string | ||
| TLS bool | ||
| TLSVerify bool | ||
| TLSOptions *tlsconfig.Options | ||
| Context string | ||
| Debug bool | ||
| Hosts []string | ||
| LogLevel string | ||
| TLS bool | ||
| TLSVerify bool | ||
| TLSOptions *tlsconfig.Options | ||
| Context string | ||
| HttpHeaders []string | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. w.r.t. the above (parsing) in mind I'm thinking if perhaps the value parsing should be part of a custom type (so that this would be an (e.g.) Thinking of which (sorry, bit hazy on that one), but I think the (Hope this helps, but happy to do some further digging in this)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically, you want to use |
||
| } | ||
|
|
||
| // NewCommonOptions returns a new CommonOptions | ||
|
|
@@ -87,6 +88,8 @@ func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) { | |
| flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to") | ||
| flags.StringVarP(&commonOpts.Context, "context", "c", "", | ||
| `Name of the context to use to connect to the daemon (overrides `+client.EnvOverrideHost+` env var and default context set with "docker context use")`) | ||
| httpHeaderOpt := opts.NewNamedListOptsRef("http-headers", &commonOpts.HttpHeaders, nil) | ||
| flags.VarP(httpHeaderOpt, "http-header", "", "Custom HTTP headers") | ||
| } | ||
|
|
||
| // SetDefaultOptions sets default values for options after flag parsing is | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
I have yet to have a closer look, but some quick thoughts;
=as separator (--http-header My-Header=myvalue)strings.SplitN(.., ..., 2)(as we expect only a single separator); this prevents issues if the value would contain:, which could be if (just thinking out loud) for example, an IPv6 address is passed (Foo-Header=[::]:123)http. CanonicalHeaderKey()(after stripping whitespace), to prevent duplicate headers, and to preventUser-Agentfrom being overridden (which we don't want); it looks like the client already does normalising (I just notice it doesn't trim whitespace, and probably should though), but it doesn't hurt to prevent possible duplicates hereOverall, I still want to look if this function (
newAPIClientFromEndpoint()) is the best place to set this; I'm considering if perhaps we should merge the config-file and flag options earlier, perhaps as part ofDockerCLI.Initialize()? (I'll have to have a look if that would work)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.
I'm trying to keep consistent with
curlsince it has been widely accepted. And I'm not sure if there are traps if we use=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.
Agree. This will make the whole configing procedure more clear
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.
Addressed