mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
account for streaming
This commit is contained in:
@@ -32,6 +32,14 @@ func (l *Logger) Middleware(next http.Handler) http.Handler {
|
|||||||
status: http.StatusOK,
|
status: http.StatusOK,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bytesRead int64
|
||||||
|
if r.Body != nil {
|
||||||
|
r.Body = &bodyCounter{
|
||||||
|
ReadCloser: r.Body,
|
||||||
|
bytesRead: &bytesRead,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve the source IP using trusted proxy configuration before passing
|
// Resolve the source IP using trusted proxy configuration before passing
|
||||||
// the request on, as the proxy will modify forwarding headers.
|
// the request on, as the proxy will modify forwarding headers.
|
||||||
sourceIp := extractSourceIP(r, l.trustedProxies)
|
sourceIp := extractSourceIP(r, l.trustedProxies)
|
||||||
@@ -53,10 +61,7 @@ func (l *Logger) Middleware(next http.Handler) http.Handler {
|
|||||||
host = r.Host
|
host = r.Host
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesUpload := r.ContentLength
|
bytesUpload := bytesRead
|
||||||
if bytesUpload < 0 {
|
|
||||||
bytesUpload = 0
|
|
||||||
}
|
|
||||||
bytesDownload := sw.bytesWritten
|
bytesDownload := sw.bytesWritten
|
||||||
|
|
||||||
entry := logEntry{
|
entry := logEntry{
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package accesslog
|
package accesslog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/proxy/internal/responsewriter"
|
"github.com/netbirdio/netbird/proxy/internal/responsewriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,3 +25,15 @@ func (w *statusWriter) Write(b []byte) (int, error) {
|
|||||||
w.bytesWritten += int64(n)
|
w.bytesWritten += int64(n)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bodyCounter wraps an io.ReadCloser and counts bytes read from the request body.
|
||||||
|
type bodyCounter struct {
|
||||||
|
io.ReadCloser
|
||||||
|
bytesRead *int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc *bodyCounter) Read(p []byte) (int, error) {
|
||||||
|
n, err := bc.ReadCloser.Read(p)
|
||||||
|
*bc.bytesRead += int64(n)
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user