Skip to content

Commit

Permalink
fix(httplog): fetch: updates to fetch interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Jul 27, 2024
1 parent c4d48e0 commit 3c1db8e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/aperturerobotics/entitygraph v0.9.1 // latest
github.com/aperturerobotics/protobuf-go-lite v0.6.5 // latest
github.com/aperturerobotics/starpc v0.33.6 // latest
github.com/aperturerobotics/util v1.25.0 // master
github.com/aperturerobotics/util v1.25.1 // latest
)

// aperture: use compatibility forks
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ github.com/aperturerobotics/quic-go v0.45.1-0.20240701204210-82dc570e7aa0 h1:KH1
github.com/aperturerobotics/quic-go v0.45.1-0.20240701204210-82dc570e7aa0/go.mod h1:X095EBMI8M7riYQRvUgegHFkEkgM2QKLvyGHyAcOw/Q=
github.com/aperturerobotics/starpc v0.33.6 h1:noc/MnmIMTek9bdEvd88QiD1p9KzEV8CUOBIoKmGgm0=
github.com/aperturerobotics/starpc v0.33.6/go.mod h1:4IYcbulEzqhPT5jKaDeL1BJPFd8WVWZ7Ugu0/348/Is=
github.com/aperturerobotics/util v1.25.0 h1:+dfi8QMsy8xzE8Xu7x3PuWSEKkrbfGZ1UHy1YffoXOw=
github.com/aperturerobotics/util v1.25.0/go.mod h1:QiSWcOha1HhCI4f48w6rd3gia9jIMGpfoeJiZMU+jLM=
github.com/aperturerobotics/util v1.25.1 h1:LOIygQIpwBNPwQDWcVT0MPuJxhJsPhPyO/YTJINy83A=
github.com/aperturerobotics/util v1.25.1/go.mod h1:m/paprtgaTiGfc4X3LkXpeseK9hfQA7QBI3cKsE/h3Y=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
Expand Down
10 changes: 5 additions & 5 deletions http/log/fetch/fetch_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package httplog_fetch

import (
"net/textproto"
"slices"
"strings"
"time"

fetch "github.com/aperturerobotics/util/js/fetch"
Expand Down Expand Up @@ -53,14 +53,14 @@ func Fetch(le *logrus.Entry, url string, opts *fetch.Opts, verbose bool) (*fetch
if le != nil {
mapSize := 1
if resp != nil {
mapSize += 1 + min(len(resp.Headers), len(logHeaders))
mapSize += 1 + min(len(resp.Header), len(logHeaders))
}
fields := make(logrus.Fields, mapSize)
fields["dur"] = duration.String()
if resp != nil {
fields["status"] = resp.Status
for hdr, hdrVal := range resp.Headers {
hdr = strings.ToLower(hdr)
for hdr, hdrVal := range resp.Header {
hdr = textproto.CanonicalMIMEHeaderKey(hdr)
if slices.Contains(logHeaders, hdr) {
fields[hdr] = hdrVal
}
Expand All @@ -69,7 +69,7 @@ func Fetch(le *logrus.Entry, url string, opts *fetch.Opts, verbose bool) (*fetch

if err != nil {
le.WithError(err).Warn("request errored")
} else if resp == nil || resp.Status >= 400 {
} else if resp == nil || resp.StatusCode >= 400 {
le.Warn("request failed")
} else if verbose {
le.Debug("request succeeded")
Expand Down
12 changes: 6 additions & 6 deletions http/log/fetch/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestFetch(t *testing.T) {
url: "https://httpbin.org/post",
opts: &fetch.Opts{
Method: "POST",
Headers: map[string]string{
"Content-Type": "application/json",
Header: map[string][]string{
"Content-Type": []string{"application/json"},
},
Body: bytes.NewReader([]byte(`{"test": "data"}`)),
},
Expand Down Expand Up @@ -68,8 +68,8 @@ func TestFetch(t *testing.T) {
if resp == nil {
t.Fatalf("Expected non-nil response, but got nil")
}
if resp.Status != http.StatusOK {
t.Errorf("Expected status %d, but got %d", http.StatusOK, resp.Status)
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected status %d, but got %v", http.StatusOK, resp.StatusCode)
}
}
})
Expand All @@ -84,7 +84,7 @@ func TestFetchWithNilLogger(t *testing.T) {
if resp == nil {
t.Fatal("Expected non-nil response, but got nil")
}
if resp.Status != http.StatusOK {
t.Errorf("Expected status %d, but got %d", http.StatusOK, resp.Status)
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected status %d, but got %d", http.StatusOK, resp.StatusCode)
}
}

0 comments on commit 3c1db8e

Please sign in to comment.