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 HTTP headers to the API client #3394

Merged
merged 2 commits into from
Oct 6, 2017

Conversation

msoderberg
Copy link
Contributor

I'm using the Go API client to access Vault through a proxy with basic auth enabled. As it is now, to send the required authorization header, you have to build each request and use RawRequest to communicate with Vault.

This change makes it possible to set headers in the client that will be used for every logical-backend API call.

@@ -399,6 +405,9 @@ func (c *Client) NewRequest(method, requestPath string) *Request {
if c.config.Timeout != 0 {
c.config.HttpClient.Timeout = c.config.Timeout
}
if c.headers != nil {
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 that this actually needs to iterate through and add headers, not replace the whole header structure unilaterally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this works now because the ToHTTP method that is called from RawRequest already does that if any headers in the passed in request is set: request.go. Before these changes no headers were set before ToHTTP was called.

It might be better to do as you suggested though. Let me know what you think and I'll update accordingly!

Copy link
Member

Choose a reason for hiding this comment

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

Ah, no -- that looks fine. Thanks for clarifying!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! No problem, thanks for merging this!

@jefferai jefferai merged commit af3022b into hashicorp:master Oct 6, 2017
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