MCPcopy Create free account
hub / github.com/containerd/nerdctl / StartHTTPServer

Function StartHTTPServer

pkg/testutil/nerdtest/utilities_linux.go:84–103  ·  view source on GitHub ↗

StartHTTPServer starts an HTTP server bound to 0.0.0.0 and returns a URL reachable from processes that cannot access 127.0.0.1 due to namespace isolation. It also returns a cleanup function that stops the server.

(handler http.Handler)

Source from the content-addressed store, hash-verified

82// from processes that cannot access 127.0.0.1 due to namespace isolation.
83// It also returns a cleanup function that stops the server.
84func StartHTTPServer(handler http.Handler) (url string, stop func(), err error) {
85 l, err := net.Listen("tcp", "0.0.0.0:0")
86 if err != nil {
87 return "", nil, err
88 }
89 srv := &httptest.Server{Config: &http.Server{Handler: handler}}
90 srv.Listener = l
91 srv.Start()
92 hostIP, herr := nettestutil.NonLoopbackIPv4()
93 if herr != nil {
94 srv.Close()
95 return "", nil, herr
96 }
97 _, port, perr := net.SplitHostPort(l.Addr().String())
98 if perr != nil {
99 srv.Close()
100 return "", nil, perr
101 }
102 return "http://" + hostIP.String() + ":" + port, func() { srv.Close() }, nil
103}

Callers 1

TestImageImportFunction · 0.92

Calls 4

NonLoopbackIPv4Function · 0.92
StartMethod · 0.80
CloseMethod · 0.45
StringMethod · 0.45

Tested by 1

TestImageImportFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…