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

Fix resty client TLS client config setting error: current transport is not an *http.Transport instance #72

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

magodo
Copy link
Owner

@magodo magodo commented Nov 20, 2023

PR #58 is not correctly done, for the oauth2 clients, which are built when the security config is set to oauth2.

In the debug log, you'll notice error current transport is not an *http.Transport instance being raised from resty, which actually is from:

func (c *Client) Transport() (*http.Transport, error) {
	if transport, ok := c.httpClient.Transport.(*http.Transport); ok {
		return transport, nil
	}
	return nil, errors.New("current transport is not an *http.Transport instance")
}

The reason is that the oauth2 client's Transport field is not a *http.Transport, but *oauth2.Transport.

To fix this, when building the client, we initially create a default http client, which is of type http.Client, and move the tls config setting and the jar setting up right after this client is built. Then based on the security setting, we further create a resty.Client wrapping this default client, or wrapping an oauth2 client, which in turns wrapping this default client.

@magodo magodo added the bug Something isn't working label Nov 20, 2023
@magodo magodo merged commit c603c4b into main Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant