NewHTTPServer starts an httptest server bound to IPv4 to avoid IPv6 listener issues in sandboxed environments.
(handler http.Handler)
| 9 | |
| 10 | // NewHTTPServer starts an httptest server bound to IPv4 to avoid IPv6 listener issues in sandboxed environments. |
| 11 | func NewHTTPServer(handler http.Handler) *httptest.Server { |
| 12 | ln, err := net.Listen("tcp4", "127.0.0.1:0") |
| 13 | if err != nil { |
| 14 | return httptest.NewServer(handler) |
| 15 | } |
| 16 | |
| 17 | srv := &httptest.Server{ |
| 18 | Listener: ln, |
| 19 | Config: &http.Server{ |
| 20 | Handler: handler, |
| 21 | }, |
| 22 | } |
| 23 | srv.Start() |
| 24 | return srv |
| 25 | } |
| 26 | |
| 27 | // NewHTTPServerT starts an httptest server bound to IPv4 and skips the test if binding fails. |
| 28 | func NewHTTPServerT(t *testing.T, handler http.Handler) *httptest.Server { |
no test coverage detected