Skip to content

Commit 5152ff5

Browse files
committed
chore: update the custom headers to remove -x prefix
Remove the -x prefix as per RFC6648. While headers are case-insensitve, making custom headers title case as per general convention. Signed-off-by: Owen Rumney <owen.rumney@aquasec.com>
1 parent 6c53a4a commit 5152ff5

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pkg/notification/notice.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ func (v *VersionChecker) RunUpdateCheck(ctx context.Context, args []string) {
8080

8181
req, err := http.NewRequestWithContext(ctx, http.MethodGet, v.updatesApi, http.NoBody)
8282
if err != nil {
83-
logger.Warn("Failed to create a request for Trivy api" log.Err(err))
83+
logger.Warn("Failed to create a request for Trivy api", log.Err(err))
8484
return
8585
}
8686

8787
// if the user hasn't disabled metrics, send the anonymous information as headers
8888
if !v.disableMetrics {
89-
req.Header.Set("-x-trivy-identifier", uniqueIdentifier())
90-
req.Header.Set("-x-trivy-command", strings.Join(args, " "))
91-
req.Header.Set("-x-trivy-os", runtime.GOOS)
92-
req.Header.Set("-x-trivy-arch", runtime.GOARCH)
89+
req.Header.Set("Trivy-Identifier", uniqueIdentifier())
90+
req.Header.Set("Trivy-Command", strings.Join(args, " "))
91+
req.Header.Set("Trivy-OS", runtime.GOOS)
92+
req.Header.Set("Trivy-Arch", runtime.GOARCH)
9393
}
9494

9595
req.Header.Set("User-Agent", fmt.Sprintf("trivy/%s", v.currentVersion))
@@ -101,7 +101,7 @@ func (v *VersionChecker) RunUpdateCheck(ctx context.Context, args []string) {
101101

102102
defer resp.Body.Close()
103103
if err := json.NewDecoder(resp.Body).Decode(&v.latestVersion); err != nil {
104-
logger.Debug(fmt.Sprintf("Failed to decode the Trivy response: %v", err))
104+
logger.Debug("Failed to decode the Trivy response", log.Err(err))
105105
return
106106
}
107107

pkg/notification/notice_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestPrintNotices(t *testing.T) {
9797

9898
// check metrics are sent
9999
require.NotNil(t, updates.lastRequest)
100-
require.NotEmpty(t, updates.lastRequest.Header.Get("-x-trivy-identifier"))
100+
require.NotEmpty(t, updates.lastRequest.Header.Get("Trivy-Identifier"))
101101
})
102102
}
103103
}
@@ -160,11 +160,11 @@ func TestCheckForNotices(t *testing.T) {
160160
if tt.expectNoMetrics {
161161
assert.True(t, v.disableMetrics)
162162
require.NotNil(t, updates.lastRequest)
163-
assert.Empty(t, updates.lastRequest.Header.Get("-x-trivy-identifier"))
163+
assert.Empty(t, updates.lastRequest.Header.Get("Trivy-Identifier"))
164164
} else {
165165
assert.False(t, v.disableMetrics)
166166
require.NotNil(t, updates.lastRequest)
167-
assert.NotEmpty(t, updates.lastRequest.Header.Get("-x-trivy-identifier"))
167+
assert.NotEmpty(t, updates.lastRequest.Header.Get("Trivy-Identifier"))
168168
}
169169

170170
})

0 commit comments

Comments
 (0)