MCPcopy Create free account
hub / github.com/dgrr/http2 / launchLocalServer

Function launchLocalServer

h2spec/h2spec_test.go:224–251  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

222}
223
224func launchLocalServer(t *testing.T) int {
225 t.Helper()
226
227 certPEM, keyPEM, err := KeyPair("test.default", time.Time{})
228 if err != nil {
229 log.Fatalf("Unable to generate certificate: %v", err)
230 }
231
232 server := &fasthttp.Server{
233 Handler: func(ctx *fasthttp.RequestCtx) {
234 ctx.Response.AppendBodyString("Test HTTP2")
235 },
236 }
237 http2.ConfigureServer(server, http2.ServerConfig{})
238
239 ln, err := net.Listen("tcp4", "127.0.0.1:0")
240 require.NoError(t, err)
241 go func() {
242 log.Println(server.ServeTLSEmbed(ln, certPEM, keyPEM))
243 }()
244
245 _, port, err := net.SplitHostPort(ln.Addr().String())
246 require.NoError(t, err)
247 portInt, err := strconv.Atoi(port)
248 require.NoError(t, err)
249
250 return portInt
251}
252
253// DefaultDomain domain for the default certificate.
254const DefaultDomain = "TEST DEFAULT CERT"

Callers 1

TestH2SpecFunction · 0.85

Calls 2

KeyPairFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected