Skip to content

Commit

Permalink
fix(net/archival): emit sorted headers
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Jul 9, 2020
1 parent 24e54f7 commit 7ba7e56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions netx/archival/archival.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"net"
"net/http"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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"
Expand Down
14 changes: 8 additions & 6 deletions netx/archival/archival_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{{
Expand Down Expand Up @@ -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",
Expand All @@ -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"},
Expand Down

0 comments on commit 7ba7e56

Please sign in to comment.