mirror of
https://github.com/creekorful/bathyscaphe
synced 2024-11-16 00:12:56 +00:00
indexer: sort headers to have deterministic output
This commit is contained in:
parent
8297dc7616
commit
69352f7237
@ -7,6 +7,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -63,9 +64,16 @@ func formatResource(url string, body string, headers map[string]string) ([]byte,
|
||||
// First URL
|
||||
builder.WriteString(fmt.Sprintf("%s\n\n", url))
|
||||
|
||||
// Sort headers to have deterministic output
|
||||
var headerNames []string
|
||||
for headerName := range headers {
|
||||
headerNames = append(headerNames, headerName)
|
||||
}
|
||||
sort.Strings(headerNames)
|
||||
|
||||
// Then headers
|
||||
for key, value := range headers {
|
||||
builder.WriteString(fmt.Sprintf("%s: %s\n", key, value))
|
||||
for _, name := range headerNames {
|
||||
builder.WriteString(fmt.Sprintf("%s: %s\n", name, headers[name]))
|
||||
}
|
||||
builder.WriteString("\n")
|
||||
|
||||
|
@ -134,7 +134,7 @@ func TestFormatResource(t *testing.T) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if string(res) != "https://google.com\n\nServer: Traefik\nContent-Type: text/html\n\nHello, world" {
|
||||
if string(res) != "https://google.com\n\nContent-Type: text/html\nServer: Traefik\n\nHello, world" {
|
||||
t.Errorf("got %s want %s", string(res), "https://google.com\n\nServer: Traefik\nContent-Type: text/html\n\nHello, world")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user