Skip to content

Commit 3c1db8e

Browse files
committed
fix(httplog): fetch: updates to fetch interfaces
Signed-off-by: Christian Stewart <[email protected]>
1 parent c4d48e0 commit 3c1db8e

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/aperturerobotics/entitygraph v0.9.1 // latest
99
github.com/aperturerobotics/protobuf-go-lite v0.6.5 // latest
1010
github.com/aperturerobotics/starpc v0.33.6 // latest
11-
github.com/aperturerobotics/util v1.25.0 // master
11+
github.com/aperturerobotics/util v1.25.1 // latest
1212
)
1313

1414
// aperture: use compatibility forks

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ github.com/aperturerobotics/quic-go v0.45.1-0.20240701204210-82dc570e7aa0 h1:KH1
2828
github.com/aperturerobotics/quic-go v0.45.1-0.20240701204210-82dc570e7aa0/go.mod h1:X095EBMI8M7riYQRvUgegHFkEkgM2QKLvyGHyAcOw/Q=
2929
github.com/aperturerobotics/starpc v0.33.6 h1:noc/MnmIMTek9bdEvd88QiD1p9KzEV8CUOBIoKmGgm0=
3030
github.com/aperturerobotics/starpc v0.33.6/go.mod h1:4IYcbulEzqhPT5jKaDeL1BJPFd8WVWZ7Ugu0/348/Is=
31-
github.com/aperturerobotics/util v1.25.0 h1:+dfi8QMsy8xzE8Xu7x3PuWSEKkrbfGZ1UHy1YffoXOw=
32-
github.com/aperturerobotics/util v1.25.0/go.mod h1:QiSWcOha1HhCI4f48w6rd3gia9jIMGpfoeJiZMU+jLM=
31+
github.com/aperturerobotics/util v1.25.1 h1:LOIygQIpwBNPwQDWcVT0MPuJxhJsPhPyO/YTJINy83A=
32+
github.com/aperturerobotics/util v1.25.1/go.mod h1:m/paprtgaTiGfc4X3LkXpeseK9hfQA7QBI3cKsE/h3Y=
3333
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
3434
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
3535
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=

http/log/fetch/fetch_js.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
package httplog_fetch
44

55
import (
6+
"net/textproto"
67
"slices"
7-
"strings"
88
"time"
99

1010
fetch "github.com/aperturerobotics/util/js/fetch"
@@ -53,14 +53,14 @@ func Fetch(le *logrus.Entry, url string, opts *fetch.Opts, verbose bool) (*fetch
5353
if le != nil {
5454
mapSize := 1
5555
if resp != nil {
56-
mapSize += 1 + min(len(resp.Headers), len(logHeaders))
56+
mapSize += 1 + min(len(resp.Header), len(logHeaders))
5757
}
5858
fields := make(logrus.Fields, mapSize)
5959
fields["dur"] = duration.String()
6060
if resp != nil {
6161
fields["status"] = resp.Status
62-
for hdr, hdrVal := range resp.Headers {
63-
hdr = strings.ToLower(hdr)
62+
for hdr, hdrVal := range resp.Header {
63+
hdr = textproto.CanonicalMIMEHeaderKey(hdr)
6464
if slices.Contains(logHeaders, hdr) {
6565
fields[hdr] = hdrVal
6666
}
@@ -69,7 +69,7 @@ func Fetch(le *logrus.Entry, url string, opts *fetch.Opts, verbose bool) (*fetch
6969

7070
if err != nil {
7171
le.WithError(err).Warn("request errored")
72-
} else if resp == nil || resp.Status >= 400 {
72+
} else if resp == nil || resp.StatusCode >= 400 {
7373
le.Warn("request failed")
7474
} else if verbose {
7575
le.Debug("request succeeded")

http/log/fetch/fetch_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func TestFetch(t *testing.T) {
3434
url: "https://httpbin.org/post",
3535
opts: &fetch.Opts{
3636
Method: "POST",
37-
Headers: map[string]string{
38-
"Content-Type": "application/json",
37+
Header: map[string][]string{
38+
"Content-Type": []string{"application/json"},
3939
},
4040
Body: bytes.NewReader([]byte(`{"test": "data"}`)),
4141
},
@@ -68,8 +68,8 @@ func TestFetch(t *testing.T) {
6868
if resp == nil {
6969
t.Fatalf("Expected non-nil response, but got nil")
7070
}
71-
if resp.Status != http.StatusOK {
72-
t.Errorf("Expected status %d, but got %d", http.StatusOK, resp.Status)
71+
if resp.StatusCode != http.StatusOK {
72+
t.Errorf("Expected status %d, but got %v", http.StatusOK, resp.StatusCode)
7373
}
7474
}
7575
})
@@ -84,7 +84,7 @@ func TestFetchWithNilLogger(t *testing.T) {
8484
if resp == nil {
8585
t.Fatal("Expected non-nil response, but got nil")
8686
}
87-
if resp.Status != http.StatusOK {
88-
t.Errorf("Expected status %d, but got %d", http.StatusOK, resp.Status)
87+
if resp.StatusCode != http.StatusOK {
88+
t.Errorf("Expected status %d, but got %d", http.StatusOK, resp.StatusCode)
8989
}
9090
}

0 commit comments

Comments
 (0)