Skip to content

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

Description

@Dray56

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Inbox

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions