Skip to content

Commit 36eeba5

Browse files
authored
Fixes the request logger reading body size from the wrong source (#63)
2 parents 1c36c0f + a213f90 commit 36eeba5

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

backend/internal/web/reception/summarizer/summarizer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func (s Summarizer) Pre(r *http.Request) string {
6363
}
6464

6565
func (s Summarizer) Post(crw *captured.ResponseWriter, start time.Time) string {
66-
return fmt.Sprintf("%s %s %s bytes",
66+
return fmt.Sprintf("%s %s %s",
6767
s.c.Magenta(crw.StatusRepresentation()),
68-
s.c.Green(time.Since(start)),
69-
s.c.Cyan(crw.Header().Get("Content-Length")),
68+
s.c.Green(fmt.Sprintf("%dµs", time.Since(start).Microseconds())),
69+
s.c.Cyan(crw.SizeRepresentation()),
7070
)
7171
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package summarizer
2+
3+
import (
4+
"fmt"
5+
"net/http/httptest"
6+
"time"
7+
8+
"logbook/internal/web/reception/captured"
9+
)
10+
11+
func ExampleSummarizer_post() {
12+
s := New(false)
13+
w := captured.New(httptest.NewRecorder())
14+
w.Write([]byte("lorem ipsum dolor sit amet"))
15+
fmt.Println(s.Post(w, time.Now().Add(-20*time.Millisecond)))
16+
// Output: 200* 20000µs 26B
17+
}

0 commit comments

Comments
 (0)