Skip to content

Commit bcdd9b4

Browse files
committed
move Content-Types to log in a map
1 parent 874b47d commit bcdd9b4

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

docs/4-read/10-vlc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The VLC shipped with Ubuntu 21.10 doesn't support playing RTSP due to a license
2121

2222
```sh
2323
sudo apt purge -y vlc
24-
snap install vlc
24+
sudo snap install vlc
2525
```
2626

2727
### Encrypted RTSP

internal/protocols/httpp/handler_logger.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@ import (
1111
)
1212

1313
const (
14-
maxDumpedRequestBodySize = 10 * 1024
14+
maxRequestBodySizeToLog = 10 * 1024
1515
)
1616

17+
var requestBodyContentTypeToLog = map[string]struct{}{
18+
"application/sdp": {},
19+
"application/trickle-ice-sdpfrag": {},
20+
}
21+
1722
func dumpRequestLimited(r *http.Request) ([]byte, error) {
18-
peek, err := io.ReadAll(io.LimitReader(r.Body, maxDumpedRequestBodySize+1))
23+
peek, err := io.ReadAll(io.LimitReader(r.Body, maxRequestBodySizeToLog+1))
1924
if err != nil {
2025
return nil, err
2126
}
2227

2328
capped := peek
24-
if int64(len(capped)) > maxDumpedRequestBodySize {
25-
capped = append([]byte(nil), capped[:maxDumpedRequestBodySize]...)
26-
capped = append(capped, []byte("\n\n(body truncated)\n")...)
29+
if int64(len(capped)) > maxRequestBodySizeToLog {
30+
capped = append([]byte(nil), capped[:maxRequestBodySizeToLog]...)
31+
capped = append(capped, []byte("\n\n(truncated body)\n")...)
2732
}
2833

2934
original := r.Body
@@ -53,7 +58,7 @@ func (w *responseRecorder) Write(b []byte) (int, error) {
5358
}
5459

5560
contentType := w.Header().Get("Content-Type")
56-
if contentType == "application/sdp" || contentType == "application/trickle-ice-sdpfrag" {
61+
if _, ok := requestBodyContentTypeToLog[contentType]; ok {
5762
w.body = append(w.body, b...)
5863
} else {
5964
w.size += len(b)

0 commit comments

Comments
 (0)