move Content-Types to log in a map (#5875)

This commit is contained in:
Alessandro Ros
2026-06-20 09:35:55 +02:00
committed by GitHub
parent 472e86d48c
commit 28d648da37
2 changed files with 12 additions and 7 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ The VLC shipped with Ubuntu 21.10 doesn't support playing RTSP due to a license
```sh
sudo apt purge -y vlc
snap install vlc
sudo snap install vlc
```
### Encrypted RTSP
+11 -6
View File
@@ -11,7 +11,7 @@ import (
)
const (
maxDumpedRequestBodySize = 10 * 1024
maxRequestBodySizeToLog = 10 * 1024
)
var requestHeadersToRedact = map[string]struct{}{
@@ -23,6 +23,11 @@ var requestHeadersToRedact = map[string]struct{}{
"X-Auth-Token": {},
}
var requestBodyContentTypeToLog = map[string]struct{}{
"application/sdp": {},
"application/trickle-ice-sdpfrag": {},
}
func cloneRequestForLogging(r *http.Request) *http.Request {
clone := r.Clone(r.Context())
clone.Header = r.Header.Clone()
@@ -37,15 +42,15 @@ func cloneRequestForLogging(r *http.Request) *http.Request {
}
func dumpRequestLimited(r *http.Request) ([]byte, error) {
peek, err := io.ReadAll(io.LimitReader(r.Body, maxDumpedRequestBodySize+1))
peek, err := io.ReadAll(io.LimitReader(r.Body, maxRequestBodySizeToLog+1))
if err != nil {
return nil, err
}
capped := peek
if int64(len(capped)) > maxDumpedRequestBodySize {
capped = append([]byte(nil), capped[:maxDumpedRequestBodySize]...)
capped = append(capped, []byte("\n\n(body truncated)\n")...)
if int64(len(capped)) > maxRequestBodySizeToLog {
capped = append([]byte(nil), capped[:maxRequestBodySizeToLog]...)
capped = append(capped, []byte("\n\n(truncated body)\n")...)
}
original := r.Body
@@ -76,7 +81,7 @@ func (w *responseRecorder) Write(b []byte) (int, error) {
}
contentType := w.Header().Get("Content-Type")
if contentType == "application/sdp" || contentType == "application/trickle-ice-sdpfrag" {
if _, ok := requestBodyContentTypeToLog[contentType]; ok {
w.body = append(w.body, b...)
} else {
w.size += len(b)