MCPcopy
hub / github.com/caddyserver/caddy / freePort

Function freePort

caddytest/integration/proxyprotocol_test.go:369–378  ·  view source on GitHub ↗

freePort returns a free local TCP port by binding briefly and releasing it.

(t *testing.T)

Source from the content-addressed store, hash-verified

367
368// freePort returns a free local TCP port by binding briefly and releasing it.
369func freePort(t *testing.T) int {
370 t.Helper()
371 ln, err := net.Listen("tcp", "127.0.0.1:0")
372 if err != nil {
373 t.Fatalf("freePort: %v", err)
374 }
375 port := ln.Addr().(*net.TCPAddr).Port
376 _ = ln.Close()
377 return port
378}
379
380// TestProxyProtocolV1WithH1 verifies that PROXY protocol v1 headers are sent
381// correctly when the transport uses HTTP/1.1 to the upstream.

Callers 2

testProxyProtocolMatrixFunction · 0.85

Calls 3

ListenMethod · 0.80
AddrMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected