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

Replace short field names with more descriptive ones. #937

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions plumbing/transport/http/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func advertisedReferences(ctx context.Context, s *session, serviceName string) (
}

type client struct {
c *http.Client
client *http.Client
transports *lru.Cache
m sync.RWMutex
mutex sync.RWMutex
}

// ClientOptions holds user configurable options for the client.
Expand Down Expand Up @@ -147,7 +147,7 @@ func NewClientWithOptions(c *http.Client, opts *ClientOptions) transport.Transpo
}
}
cl := &client{
c: c,
client: c,
}

if opts != nil {
Expand Down Expand Up @@ -234,10 +234,10 @@ func newSession(c *client, ep *transport.Endpoint, auth transport.AuthMethod) (*
// if the client wasn't configured to have a cache for transports then just configure
// the transport and use it directly, otherwise try to use the cache.
if c.transports == nil {
tr, ok := c.c.Transport.(*http.Transport)
tr, ok := c.client.Transport.(*http.Transport)
if !ok {
return nil, fmt.Errorf("expected underlying client transport to be of type: %s; got: %s",
reflect.TypeOf(transport), reflect.TypeOf(c.c.Transport))
reflect.TypeOf(transport), reflect.TypeOf(c.client.Transport))
}

transport = tr.Clone()
Expand All @@ -258,20 +258,20 @@ func newSession(c *client, ep *transport.Endpoint, auth transport.AuthMethod) (*
transport, found = c.fetchTransport(transportOpts)

if !found {
transport = c.c.Transport.(*http.Transport).Clone()
transport = c.client.Transport.(*http.Transport).Clone()
configureTransport(transport, ep)
c.addTransport(transportOpts, transport)
}
}

httpClient = &http.Client{
Transport: transport,
CheckRedirect: c.c.CheckRedirect,
Jar: c.c.Jar,
Timeout: c.c.Timeout,
CheckRedirect: c.client.CheckRedirect,
Jar: c.client.Jar,
Timeout: c.client.Timeout,
}
} else {
httpClient = c.c
httpClient = c.client
}

s := &session{
Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/http/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *UploadPackSuite) TestNewClient(c *C) {
cl := &http.Client{Transport: roundTripper}
r, ok := NewClient(cl).(*client)
c.Assert(ok, Equals, true)
c.Assert(r.c, Equals, cl)
c.Assert(r.client, Equals, cl)
}

func (s *ClientSuite) TestNewBasicAuth(c *C) {
Expand Down
12 changes: 6 additions & 6 deletions plumbing/transport/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ type transportOptions struct {
}

func (c *client) addTransport(opts transportOptions, transport *http.Transport) {
c.m.Lock()
c.mutex.Lock()
c.transports.Add(opts, transport)
c.m.Unlock()
c.mutex.Unlock()
}

func (c *client) removeTransport(opts transportOptions) {
c.m.Lock()
c.mutex.Lock()
c.transports.Remove(opts)
c.m.Unlock()
c.mutex.Unlock()
}

func (c *client) fetchTransport(opts transportOptions) (*http.Transport, bool) {
c.m.RLock()
c.mutex.RLock()
t, ok := c.transports.Get(opts)
c.m.RUnlock()
c.mutex.RUnlock()
if !ok {
return nil, false
}
Expand Down