Skip to content

Commit

Permalink
cleanup: headers map now uses ArchivalMaybeBinaryString (#1333)
Browse files Browse the repository at this point in the history
This diff modifies the headers-as-a-map representation such that we use
ArchivalMaybeBinaryString instead of ArchivalMaybeBinaryData.

The overall idea is to migrate all users of the latter to the former,
such that we can remove the latter and implement extra scrubbing for all
ArchivalMaybeBinaryString users.

Part of ooni/probe#2531
  • Loading branch information
bassosimone authored Sep 28, 2023
1 parent 3a350e8 commit af68086
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 167 deletions.
16 changes: 8 additions & 8 deletions internal/experiment/hhfm/hhfm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,9 @@ func TestNewRequestEntryList(t *testing.T) {
Key: "User-aGENT",
Value: tracex.MaybeBinaryValue{Value: "foo/1.0"},
}},
Headers: map[string]tracex.MaybeBinaryValue{
"ContENt-tYPE": {Value: "text/plain"},
"User-aGENT": {Value: "foo/1.0"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"ContENt-tYPE": "text/plain",
"User-aGENT": "foo/1.0",
},
Method: "GeT",
URL: "http://10.0.0.1/",
Expand All @@ -773,7 +773,7 @@ func TestNewRequestEntryList(t *testing.T) {
wantOut: []tracex.RequestEntry{{
Request: tracex.HTTPRequest{
Method: "GeT",
Headers: make(map[string]tracex.MaybeBinaryValue),
Headers: make(map[string]model.ArchivalMaybeBinaryString),
HeadersList: []tracex.HTTPHeader{},
URL: "http://10.0.0.1/",
},
Expand Down Expand Up @@ -820,9 +820,9 @@ func TestNewHTTPResponse(t *testing.T) {
Key: "User-Agent",
Value: tracex.MaybeBinaryValue{Value: "foo/1.0"},
}},
Headers: map[string]tracex.MaybeBinaryValue{
"Content-Type": {Value: "text/plain"},
"User-Agent": {Value: "foo/1.0"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Content-Type": "text/plain",
"User-Agent": "foo/1.0",
},
},
}, {
Expand All @@ -834,7 +834,7 @@ func TestNewHTTPResponse(t *testing.T) {
Body: model.ArchivalMaybeBinaryString(""),
Code: 200,
HeadersList: []tracex.HTTPHeader{},
Headers: map[string]tracex.MaybeBinaryValue{},
Headers: map[string]model.ArchivalMaybeBinaryString{},
},
}}
for _, tt := range tests {
Expand Down
118 changes: 59 additions & 59 deletions internal/experiment/webconnectivity/httpanalysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"Date": {Value: "Mon Jul 13 21:10:08 CEST 2020"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Date": "Mon Jul 13 21:10:08 CEST 2020",
},
Code: 200,
},
Expand All @@ -382,8 +382,8 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"Date": {Value: "Mon Jul 13 21:10:08 CEST 2020"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Date": "Mon Jul 13 21:10:08 CEST 2020",
},
Code: 200,
},
Expand All @@ -402,8 +402,8 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"Date": {Value: "Mon Jul 13 21:10:08 CEST 2020"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Date": "Mon Jul 13 21:10:08 CEST 2020",
},
Code: 200,
},
Expand All @@ -425,9 +425,9 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"Date": {Value: "Mon Jul 13 21:10:08 CEST 2020"},
"Antani": {Value: "MASCETTI"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Date": "Mon Jul 13 21:10:08 CEST 2020",
"Antani": "MASCETTI",
},
Code: 200,
},
Expand All @@ -450,9 +450,9 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"Date": {Value: "Mon Jul 13 21:10:08 CEST 2020"},
"Antani": {Value: "MASCETTI"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Date": "Mon Jul 13 21:10:08 CEST 2020",
"Antani": "MASCETTI",
},
Code: 200,
},
Expand All @@ -475,19 +475,19 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"Accept-Ranges": {Value: "bytes"},
"Age": {Value: "404727"},
"Cache-Control": {Value: "max-age=604800"},
"Content-Length": {Value: "1256"},
"Content-Type": {Value: "text/html; charset=UTF-8"},
"Date": {Value: "Tue, 14 Jul 2020 22:26:09 GMT"},
"Etag": {Value: "\"3147526947\""},
"Expires": {Value: "Tue, 21 Jul 2020 22:26:09 GMT"},
"Last-Modified": {Value: "Thu, 17 Oct 2019 07:18:26 GMT"},
"Server": {Value: "ECS (dcb/7F3C)"},
"Vary": {Value: "Accept-Encoding"},
"X-Cache": {Value: "HIT"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Accept-Ranges": "bytes",
"Age": "404727",
"Cache-Control": "max-age=604800",
"Content-Length": "1256",
"Content-Type": "text/html; charset=UTF-8",
"Date": "Tue, 14 Jul 2020 22:26:09 GMT",
"Etag": "\"3147526947\"",
"Expires": "Tue, 21 Jul 2020 22:26:09 GMT",
"Last-Modified": "Thu, 17 Oct 2019 07:18:26 GMT",
"Server": "ECS (dcb/7F3C)",
"Vary": "Accept-Encoding",
"X-Cache": "HIT",
},
Code: 200,
},
Expand Down Expand Up @@ -522,18 +522,18 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"Accept-Ranges": {Value: "bytes"},
"Age": {Value: "404727"},
"Cache-Control": {Value: "max-age=604800"},
"Content-Length": {Value: "1256"},
"Content-Type": {Value: "text/html; charset=UTF-8"},
"Date": {Value: "Tue, 14 Jul 2020 22:26:09 GMT"},
"Etag": {Value: "\"3147526947\""},
"Expires": {Value: "Tue, 21 Jul 2020 22:26:09 GMT"},
"Last-Modified": {Value: "Thu, 17 Oct 2019 07:18:26 GMT"},
"Server": {Value: "ECS (dcb/7F3C)"},
"Vary": {Value: "Accept-Encoding"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Accept-Ranges": "bytes",
"Age": "404727",
"Cache-Control": "max-age=604800",
"Content-Length": "1256",
"Content-Type": "text/html; charset=UTF-8",
"Date": "Tue, 14 Jul 2020 22:26:09 GMT",
"Etag": "\"3147526947\"",
"Expires": "Tue, 21 Jul 2020 22:26:09 GMT",
"Last-Modified": "Thu, 17 Oct 2019 07:18:26 GMT",
"Server": "ECS (dcb/7F3C)",
"Vary": "Accept-Encoding",
},
Code: 200,
},
Expand Down Expand Up @@ -567,17 +567,17 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"Accept-Ranges": {Value: "bytes"},
"Age": {Value: "404727"},
"Cache-Control": {Value: "max-age=604800"},
"Content-Type": {Value: "text/html; charset=UTF-8"},
"Date": {Value: "Tue, 14 Jul 2020 22:26:09 GMT"},
"Etag": {Value: "\"3147526947\""},
"Expires": {Value: "Tue, 21 Jul 2020 22:26:09 GMT"},
"Last-Modified": {Value: "Thu, 17 Oct 2019 07:18:26 GMT"},
"Server": {Value: "ECS (dcb/7F3C)"},
"Vary": {Value: "Accept-Encoding"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Accept-Ranges": "bytes",
"Age": "404727",
"Cache-Control": "max-age=604800",
"Content-Type": "text/html; charset=UTF-8",
"Date": "Tue, 14 Jul 2020 22:26:09 GMT",
"Etag": "\"3147526947\"",
"Expires": "Tue, 21 Jul 2020 22:26:09 GMT",
"Last-Modified": "Thu, 17 Oct 2019 07:18:26 GMT",
"Server": "ECS (dcb/7F3C)",
"Vary": "Accept-Encoding",
},
Code: 200,
},
Expand Down Expand Up @@ -608,17 +608,17 @@ func TestHeadersMatch(t *testing.T) {
tk: urlgetter.TestKeys{
Requests: []tracex.RequestEntry{{
Response: tracex.HTTPResponse{
Headers: map[string]tracex.MaybeBinaryValue{
"accept-ranges": {Value: "bytes"},
"AGE": {Value: "404727"},
"cache-Control": {Value: "max-age=604800"},
"Content-TyPe": {Value: "text/html; charset=UTF-8"},
"DatE": {Value: "Tue, 14 Jul 2020 22:26:09 GMT"},
"etag": {Value: "\"3147526947\""},
"expires": {Value: "Tue, 21 Jul 2020 22:26:09 GMT"},
"Last-Modified": {Value: "Thu, 17 Oct 2019 07:18:26 GMT"},
"SerVer": {Value: "ECS (dcb/7F3C)"},
"Vary": {Value: "Accept-Encoding"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"accept-ranges": "bytes",
"AGE": "404727",
"cache-Control": "max-age=604800",
"Content-TyPe": "text/html; charset=UTF-8",
"DatE": "Tue, 14 Jul 2020 22:26:09 GMT",
"etag": "\"3147526947\"",
"expires": "Tue, 21 Jul 2020 22:26:09 GMT",
"Last-Modified": "Thu, 17 Oct 2019 07:18:26 GMT",
"SerVer": "ECS (dcb/7F3C)",
"Vary": "Accept-Encoding",
},
Code: 200,
},
Expand Down
24 changes: 12 additions & 12 deletions internal/legacy/tracex/archival_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ func TestNewRequestList(t *testing.T) {
Value: "miniooni/0.1.0-dev",
},
}},
Headers: map[string]MaybeBinaryValue{
"User-Agent": {Value: "miniooni/0.1.0-dev"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"User-Agent": "miniooni/0.1.0-dev",
},
Method: "GET",
URL: "https://www.example.com/result",
},
Response: HTTPResponse{
HeadersList: []HTTPHeader{},
Headers: make(map[string]MaybeBinaryValue),
Headers: make(map[string]model.ArchivalMaybeBinaryString),
},
T: 0.02,
}, {
Expand All @@ -198,8 +198,8 @@ func TestNewRequestList(t *testing.T) {
Value: "miniooni/0.1.0-dev",
},
}},
Headers: map[string]MaybeBinaryValue{
"User-Agent": {Value: "miniooni/0.1.0-dev"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"User-Agent": "miniooni/0.1.0-dev",
},
Method: "POST",
URL: "https://www.example.com/submit",
Expand All @@ -213,8 +213,8 @@ func TestNewRequestList(t *testing.T) {
Value: "miniooni/0.1.0-dev",
},
}},
Headers: map[string]MaybeBinaryValue{
"Server": {Value: "miniooni/0.1.0-dev"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Server": "miniooni/0.1.0-dev",
},
Locations: nil,
},
Expand Down Expand Up @@ -248,8 +248,8 @@ func TestNewRequestList(t *testing.T) {
Value: "miniooni/0.1.0-dev",
},
}},
Headers: map[string]MaybeBinaryValue{
"User-Agent": {Value: "miniooni/0.1.0-dev"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"User-Agent": "miniooni/0.1.0-dev",
},
Method: "GET",
URL: "https://www.example.com/",
Expand All @@ -272,9 +272,9 @@ func TestNewRequestList(t *testing.T) {
Value: "miniooni/0.1.0-dev",
},
}},
Headers: map[string]MaybeBinaryValue{
"Server": {Value: "miniooni/0.1.0-dev"},
"Location": {Value: "https://x.example.com"},
Headers: map[string]model.ArchivalMaybeBinaryString{
"Server": "miniooni/0.1.0-dev",
"Location": "https://x.example.com",
},
Locations: []string{
"https://x.example.com", "https://y.example.com",
Expand Down
4 changes: 2 additions & 2 deletions internal/measurexlite/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func newHTTPRequestHeaderList(req *http.Request) []model.ArchivalHTTPHeader {

// newHTTPRequestHeaderMap calls newHTTPHeaderMap with the request headers or
// return an empty map in case the request is nil.
func newHTTPRequestHeaderMap(req *http.Request) map[string]model.ArchivalMaybeBinaryData {
func newHTTPRequestHeaderMap(req *http.Request) map[string]model.ArchivalMaybeBinaryString {
m := http.Header{}
if req != nil {
m = req.Header
Expand Down Expand Up @@ -139,7 +139,7 @@ func newHTTPResponseHeaderList(resp *http.Response) (out []model.ArchivalHTTPHea

// newHTTPResponseHeaderMap calls newHTTPHeaderMap with the request headers or
// return an empty map in case the request is nil.
func newHTTPResponseHeaderMap(resp *http.Response) (out map[string]model.ArchivalMaybeBinaryData) {
func newHTTPResponseHeaderMap(resp *http.Response) (out map[string]model.ArchivalMaybeBinaryString) {
m := http.Header{}
if resp != nil {
m = resp.Header
Expand Down
Loading

0 comments on commit af68086

Please sign in to comment.