Skip to content

Commit

Permalink
Merge pull request #7 from mailgun/thrawn/develop
Browse files Browse the repository at this point in the history
Fix HTTPPoolOptions.Transport
  • Loading branch information
thrawn01 authored Jun 4, 2019
2 parents 554745c + 2869a0c commit c201503
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0-rc.2] - 2019-06-03
## [2.0.0-rc.3] - 2019-06-03
### Changes
* Now using golang standard `context.Context` instead of `groupcache.Context`.
* HTTP requests made by `httpGetter` now respect `context.Context` done.
* Moved `HTTPPool` config `Context` and `Transport` to `HTTPPoolOptions` for consist configuration.
* Now Associating the transport with peer `httpGetter` so we take advantage of
connection reuse. This lowers the impact on DNS and improves performance for
high request volume low latency applications.
* Now Associating the transport with peer `httpGetter` so there is no need to
call `Transport` function for each request.
* Now always populating the hotcache. A more complex algorithm is unnecessary
when the LRU cache will ensure the most used values remain in the cache. The
evict code ensures the hotcache does not overcrowd the maincache.
* Changed import paths to /v2 in accordance with go modules rules
* Fixed Issue where `DefaultTransport` was always used even if `Transport` was
specified by the user.

## [1.3.0] - 2019-05-23
### Added
Expand Down
14 changes: 8 additions & 6 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ func (p *HTTPPool) Set(peers ...string) {
p.peers.Add(peers...)
p.httpGetters = make(map[string]*httpGetter, len(peers))
for _, peer := range peers {
p.httpGetters[peer] = &httpGetter{getTransport: p.opts.Transport, baseURL: peer + p.opts.BasePath}
p.httpGetters[peer] = &httpGetter{
getTransport: p.opts.Transport,
baseURL: peer + p.opts.BasePath,
}
}
}

Expand Down Expand Up @@ -242,15 +245,14 @@ func (h *httpGetter) makeRequest(ctx context.Context, method string, in *pb.GetR
// Pass along the context to the RoundTripper
req = req.WithContext(ctx)

// Associate the transport with this peer so we take advantage of connection reuse.
// Associate the transport with this peer so we don't need to
// call getTransport() every time a request is made.
if h.transport == nil {
if h.getTransport != nil {
h.transport = h.getTransport(ctx)
} else {
h.transport = http.DefaultTransport
}
// Ensure we have a copy of the default transport and not just a reference.
tr := http.DefaultTransport.(*http.Transport)
trCopy := http.Transport(*tr)
h.transport = &trCopy
}

res, err := h.transport.RoundTrip(req)
Expand Down

0 comments on commit c201503

Please sign in to comment.