Documentation ¶
Overview ¶
Package singleshot provides an http.RoundTripper which deduplicates similar HTTP requests.
If two similar HTTP requests are supposed to be sent concurrently, the first one will actually be sent to the server, while the second one waits until the first one was fulfilled completely. The second request will never be sent to the server, but returns a copy of the response of the first request.
Req 1 -----------------> Resp 1 Req 2 ----> Resp 1' Req 3 -------------> Resp 3
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is safe for concurrent use.
func NewTransport ¶
func NewTransport(transport http.RoundTripper) *Transport
NewTransport creates a new instance of singleshot.Transport.
Example ¶
package main import ( "net/http" "github.com/joeig/singleshot" ) func main() { _ = http.Client{ Transport: singleshot.NewTransport(http.DefaultTransport), } }
Output:
func (*Transport) RoundTrip ¶
RoundTrip deduplicates similar subsequential HTTP requests, if the first request of a kind has not been completely fulfilled yet.
Only "GET" requests (excluding "range" requests) are deduplicated, other requests are passed. Request are considered similar, if they share the same method and request URI (see RFC 2616, section 9.3).
Always apply proper timeouts or use requests with contexts, otherwise one request which is timing out may stop subsequent requests from being retried.
While the response body is a valid io.ReadCloser, the transfer itself has finished.