felixge / felixge/httpsnoop

avoid multiple wrapping

未關閉
#19 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Go
星號
1.2k
分支
48
PR 合併指標
30 天內沒有已合併 PR

描述

Since it's possible to have multiple uses of httpsnoop in a project, coming from different imported modules (e.g. when using [server-timing](https://github.com/mitchellh/go-server-timing)), it's also possible to end up wrapping a `ResponseWriter` multiple times. This is not ideal because it has a sensible performance impact:
```
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkBaseline
BenchmarkBaseline-8 745539247 1.477 ns/op 0 B/op 0 allocs/op
BenchmarkCaptureMetrics
BenchmarkCaptureMetrics-8 3790958 296.2 ns/op 225 B/op 7 allocs/op
BenchmarkCaptureMetricsTwice
BenchmarkCaptureMetricsTwice-8 1912039 581.3 ns/op 450 B/op 14 allocs/op
```
(these benchmarks were made after switching `httptest.NewServer` for direct `h.ServeHTTP` calls, in order to avoid the unrelated overhead of the server; see #20 )

Ideally we'd return the same `Metrics` instance when re-wrapping an already wrapped `ResponseWriter`.

In case we explicitly want to measure at two different places in the middleware-chain, we'd still be able to `Unwrap` before re-wrapping.

WDYT?

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。