MCPcopy
hub / github.com/SurgeDM/Surge / NewHTTPServer

Function NewHTTPServer

internal/testutil/http_server.go:11–25  ·  view source on GitHub ↗

NewHTTPServer starts an httptest server bound to IPv4 to avoid IPv6 listener issues in sandboxed environments.

(handler http.Handler)

Source from the content-addressed store, hash-verified

9
10// NewHTTPServer starts an httptest server bound to IPv4 to avoid IPv6 listener issues in sandboxed environments.
11func 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.
28func NewHTTPServerT(t *testing.T, handler http.Handler) *httptest.Server {

Callers 2

NewMockServerFunction · 0.85
NewStreamingMockServerFunction · 0.85

Calls 1

StartMethod · 0.80

Tested by

no test coverage detected