From da7d8cb26d97d8b797732cc0dcb697edffb693cd Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 18 Dec 2023 14:54:52 -0500 Subject: [PATCH] httpcaddyfile: Sort skip_hosts for deterministic JSON (#5990) * httpcaddyfile: Sort skip_hosts for deterministic JSON * Update caddyconfig/httpcaddyfile/httptype.go Co-authored-by: Mohammed Al Sahaf * Fix test * Bah --------- Co-authored-by: Mohammed Al Sahaf --- caddyconfig/httpcaddyfile/httptype.go | 5 +++++ caddytest/integration/caddyfile_adapt/log_skip_hosts.txt | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index c82d92efc..cb3095a16 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -820,6 +820,11 @@ func (st *ServerType) serversFromPairings( } } + // sort for deterministic JSON output + if srv.Logs != nil { + slices.Sort(srv.Logs.SkipHosts) + } + // a server cannot (natively) serve both HTTP and HTTPS at the // same time, so make sure the configuration isn't in conflict err := detectConflictingSchemes(srv, p.serverBlocks, options) diff --git a/caddytest/integration/caddyfile_adapt/log_skip_hosts.txt b/caddytest/integration/caddyfile_adapt/log_skip_hosts.txt index 25e4bd1c2..8fdd57156 100644 --- a/caddytest/integration/caddyfile_adapt/log_skip_hosts.txt +++ b/caddytest/integration/caddyfile_adapt/log_skip_hosts.txt @@ -66,9 +66,9 @@ example.com { "one.example.com": "" }, "skip_hosts": [ + "example.com", "three.example.com", - "two.example.com", - "example.com" + "two.example.com" ] } }