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

No support for adding user-agent field or custom header to json_client #105

Open
Dray56 opened this issue Dec 30, 2024 · 0 comments
Open

Comments

@Dray56
Copy link

Dray56 commented Dec 30, 2024

Proposed Change

In the terraform-provider-cloudfoundry, we are planning to make use of the policy_client which in turn uses the json_client for making requests. The provider supports the option of adding custom user-agents as a header and expects the underlying clients to propagate that in the requests.

However for the policy_client, there is no such option as the json_client itself does not support any such custom headers which are widely supported in most of the other clients.

There should be some way to add the user-agent and propagate that in the requests.

type JsonClient interface {
	Do(method, route string, reqData, respData interface{}, token string, userAgent string) error
	CloseIdleConnections()
}

func (c *Client) Do(method, route string, reqData, respData interface{}, token string, userAgent string) error {
...........
	if userAgent != "" {
		request.Header.Add("User-Agent", userAgent)
	}
	resp, err := c.HttpClient.Do(request)
...........
}

or add it in the client structure and invoke accordingly

type Client struct {
	Logger      lager.Logger
	HttpClient  HttpClient
	Url         string
        UserAgent   string
	Marshaler   marshal.Marshaler
	Unmarshaler marshal.Unmarshaler
}

func (c *Client) Do(method, route string, reqData, respData interface{}, token string) error {
...........
	if c.UserAgent != "" {
		request.Header.Add("User-Agent", c.UserAgent)
	}
	resp, err := c.HttpClient.Do(request)
...........
}

Acceptance criteria

.

Related links

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant