Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.46 KB

README.md

File metadata and controls

42 lines (29 loc) · 1.46 KB

Singleshot

Singleshot provides an http.RoundTripper which deduplicates similar HTTP requests.

Go Report Card PkgGoDev

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

Usage

package main

import (
	"net/http"

	"go.eigsys.de/singleshot"
)

func main() {
	_ = http.Client{
		Transport: singleshot.NewTransport(http.DefaultTransport),
	}
}

Notes

  • 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 a range request. The body is ignored according to RFC 2616, section 9.3.

Documentation

See GoDoc.