-
Notifications
You must be signed in to change notification settings - Fork 460
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
Transport wrappers #2103
Transport wrappers #2103
Conversation
164b58f
to
0545598
Compare
func (w *Webhook) DoWithContext(ctx context.Context, client *http.Client, reqBody *webhook.RequestBody, data any) (*webhook.ResponseBody, error) { | ||
// TransportWrapper wraps the set of functions mapping [http.Transport] references to | ||
// [http.RoundTripper]. | ||
type TransportWrapper = httptransport.Wrapper |
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.
What is this for?
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.
The httptransport
package is an internal one, to avoid duplication from package to package. Since the function's signature is inside function definitions I thought to compress the signature by declaring a type alias.
authority/provisioner/provisioner.go
Outdated
@@ -264,6 +264,9 @@ type Config struct { | |||
// HTTPClient is an HTTP client that trusts the system cert pool and the CA | |||
// roots. | |||
HTTPClient *http.Client | |||
// WrapTransport references the function that should wrap any [http.Transport] initialized | |||
// down the Config's chain. | |||
WrapTransport func(*http.Transport) http.RoundTripper |
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.
Why not httptransport.Wrapper
?
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.
Well, it'll be a type alias but it's coming right up.
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.
@@ -103,6 +104,22 @@ func WithWebhookClient(c *http.Client) Option { | |||
} | |||
} | |||
|
|||
// Wrapper wraps the set of functions mapping [http.Transport] references to [http.RoundTripper]. | |||
type TransportWrapper = httptransport.Wrapper |
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.
What's this for?
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.
See above the above.
This PR adds references to a transport wrapper that callers may pass in order to inject their own dependecies to references of HTTP clients that the internal packages generate.