Skip to content

Commit

Permalink
chore: http.StatusOK header by default
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <[email protected]>
  • Loading branch information
rustatian committed Sep 11, 2023
1 parent f385cc6 commit f9245af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdO
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/roadrunner-server/api/v4 v4.7.1 h1:BYU2n92mcVyanV4w3fBSSztfP8ILUh5IyndRI1UD2/8=
github.com/roadrunner-server/api/v4 v4.7.1/go.mod h1:Ut9T2j3E22cnRJtipbU8N3WVhyV040iiDfddzojlKwY=
github.com/roadrunner-server/api/v4 v4.8.0 h1:wsANwein0dD3q9OQi8L6XGjgEkEn/23mAJ4ZphavfLM=
github.com/roadrunner-server/api/v4 v4.8.0/go.mod h1:FhCdSyHWBJfyZ0yuggVE72WYKcmAOsGuJbC3dvzaMOg=
github.com/roadrunner-server/endure/v2 v2.4.2 h1:aFnPc321l5HDzE2mN5wwfksJ40lgXwfU3RSqdS1LyUQ=
Expand Down
16 changes: 6 additions & 10 deletions middleware/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ var _ http.ResponseWriter = (*wrapper)(nil)

type wrapper struct {
io.ReadCloser
read int
write int
headerWritten bool
read int
write int

w http.ResponseWriter
code int
Expand All @@ -34,12 +33,7 @@ func (w *wrapper) Read(b []byte) (int, error) {
}

func (w *wrapper) WriteHeader(code int) {
if w.headerWritten {
return
}

w.code = code
w.headerWritten = true
w.w.WriteHeader(code)
}

Expand Down Expand Up @@ -72,7 +66,7 @@ func (w *wrapper) Close() error {
}

func (w *wrapper) reset() {
w.code = 0
w.code = http.StatusOK
w.read = 0
w.write = 0
w.w = nil
Expand All @@ -90,7 +84,9 @@ func NewLogMiddleware(next http.Handler, accessLogs bool, log *zap.Logger) http.
log: log,
pool: sync.Pool{
New: func() any {
return &wrapper{}
return &wrapper{
code: http.StatusOK,
}
},
},
}
Expand Down

0 comments on commit f9245af

Please sign in to comment.