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
package main
import (
"net/http"
"go.eigsys.de/singleshot"
)
func main() {
_ = http.Client{
Transport: singleshot.NewTransport(http.DefaultTransport),
}
}
- Always apply proper timeouts or use requests with contexts, otherwise one request which is timing out may stop subsequent requests from being retried.
- Requests are considered deduplicatable, if they share the same HTTP method and request URI. Furthermore, the method has to be
GET
and the request must not be arange
request. The body is ignored according to RFC 2616, section 9.3.
See GoDoc.