From 7ba7e569294595fac84c420a6cfd80941d7cb180 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 9 Jul 2020 12:51:40 +0200 Subject: [PATCH] fix(net/archival): emit sorted headers See failing test https://github.com/ooni/probe-engine/pull/751/checks?check_run_id=853562310 Spotted as part of https://github.com/ooni/probe-engine/issues/740 --- netx/archival/archival.go | 4 ++++ netx/archival/archival_test.go | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/netx/archival/archival.go b/netx/archival/archival.go index b5dc251b..844c4274 100644 --- a/netx/archival/archival.go +++ b/netx/archival/archival.go @@ -11,6 +11,7 @@ import ( "fmt" "net" "net/http" + "sort" "strconv" "strings" "time" @@ -304,6 +305,9 @@ func addheaders( }) } } + sort.Slice(*destList, func(i, j int) bool { + return (*destList)[i].Key < (*destList)[j].Key + }) } // NewRequestList returns the list for "requests" diff --git a/netx/archival/archival_test.go b/netx/archival/archival_test.go index 99f730e8..cd975e6c 100644 --- a/netx/archival/archival_test.go +++ b/netx/archival/archival_test.go @@ -201,7 +201,9 @@ func TestNewRequestList(t *testing.T) { T: 0.01, }}, }, { - name: "run with redirect", + // for an example of why we need to sort headers, see + // https://github.com/ooni/probe-engine/pull/751/checks?check_run_id=853562310 + name: "run with redirect and headers to sort", args: args{ begin: begin, events: []trace.Event{{ @@ -242,11 +244,6 @@ func TestNewRequestList(t *testing.T) { Response: archival.HTTPResponse{ Code: 302, HeadersList: []archival.HTTPHeader{{ - Key: "Server", - Value: archival.MaybeBinaryValue{ - Value: "orchestra/0.1.0-dev", - }, - }, { Key: "Location", Value: archival.MaybeBinaryValue{ Value: "https://x.example.com", @@ -256,6 +253,11 @@ func TestNewRequestList(t *testing.T) { Value: archival.MaybeBinaryValue{ Value: "https://y.example.com", }, + }, { + Key: "Server", + Value: archival.MaybeBinaryValue{ + Value: "orchestra/0.1.0-dev", + }, }}, Headers: map[string]archival.MaybeBinaryValue{ "Server": {Value: "orchestra/0.1.0-dev"},