@@ -11,19 +11,24 @@ import (
1111)
1212
1313const (
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+
1722func 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