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

Function proxyProtoConfig

caddytest/integration/proxyprotocol_test.go:324–366  ·  view source on GitHub ↗

proxyProtoConfig builds a Caddy JSON configuration that: - listens on listenPort for inbound HTTP requests - proxies them to backendAddr with PROXY protocol ppVersion ("v1"/"v2") - uses the given transport versions (e.g. ["1.1"] or ["h2c"])

(listenPort int, backendAddr, ppVersion string, transportVersions []string)

Source from the content-addressed store, hash-verified

322// - proxies them to backendAddr with PROXY protocol ppVersion ("v1"/"v2")
323// - uses the given transport versions (e.g. ["1.1"] or ["h2c"])
324func proxyProtoConfig(listenPort int, backendAddr, ppVersion string, transportVersions []string) string {
325 versionsJSON, _ := json.Marshal(transportVersions)
326 return fmt.Sprintf(`{
327 "admin": {
328 "listen": "localhost:2999"
329 },
330 "apps": {
331 "pki": {
332 "certificate_authorities": {
333 "local": {
334 "install_trust": false
335 }
336 }
337 },
338 "http": {
339 "grace_period": 1,
340 "servers": {
341 "proxy": {
342 "listen": [":%d"],
343 "automatic_https": {
344 "disable": true
345 },
346 "routes": [
347 {
348 "handle": [
349 {
350 "handler": "reverse_proxy",
351 "upstreams": [{"dial": "%s"}],
352 "transport": {
353 "protocol": "http",
354 "proxy_protocol": "%s",
355 "versions": %s
356 }
357 }
358 ]
359 }
360 ]
361 }
362 }
363 }
364 }
365 }`, listenPort, backendAddr, ppVersion, string(versionsJSON))
366}
367
368// freePort returns a free local TCP port by binding briefly and releasing it.
369func freePort(t *testing.T) int {

Callers 1

testProxyProtocolMatrixFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected