aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/http/transport.go
diff options
context:
space:
mode:
authorSanskar Jaiswal <jaiswalsanskar078@gmail.com>2023-04-18 16:31:58 +0530
committerSanskar Jaiswal <jaiswalsanskar078@gmail.com>2023-05-04 11:53:09 +0530
commit399b1ec2d598b7950816727b8d92e8580553372c (patch)
treecdeb8c7a77d2ccd39df9f3a04e8a79546276c993 /plumbing/transport/http/transport.go
parent223727feb195642234a600040b12a2d3597d0989 (diff)
downloadgo-git-399b1ec2d598b7950816727b8d92e8580553372c.tar.gz
plumbing: transport/http, refactor transport to cache underlying transport objects
Refactor the in-built http transport to cache the underlying http transport objects mapped to its specific options for each Git transport object. This lets us reuse the transport for a specific set of configurations as recommended. (ref: https://pkg.go.dev/net/http#Transport) If there are no transport specific options provided, the default transport is used. Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
Diffstat (limited to 'plumbing/transport/http/transport.go')
-rw-r--r--plumbing/transport/http/transport.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/plumbing/transport/http/transport.go b/plumbing/transport/http/transport.go
new file mode 100644
index 0000000..cd6787a
--- /dev/null
+++ b/plumbing/transport/http/transport.go
@@ -0,0 +1,38 @@
+package http
+
+import (
+ "net/http"
+)
+
+// transportOptions contains transport specific configuration.
+type transportOptions struct {
+ insecureSkipTLS bool
+ // []byte is not comparable.
+ caBundle string
+}
+
+func (c *client) addTransport(opts transportOptions, transport *http.Transport) {
+ c.m.Lock()
+ c.transports.Add(opts, transport)
+ c.m.Unlock()
+}
+
+func (c *client) removeTransport(opts transportOptions) {
+ c.m.Lock()
+ c.transports.Remove(opts)
+ c.m.Unlock()
+}
+
+func (c *client) fetchTransport(opts transportOptions) (*http.Transport, bool) {
+ c.m.RLock()
+ t, ok := c.transports.Get(opts)
+ c.m.RUnlock()
+ if !ok {
+ return nil, false
+ }
+ transport, ok := t.(*http.Transport)
+ if !ok {
+ return nil, false
+ }
+ return transport, true
+}