update: limit logBrief http body size (#3498)

Co-authored-by: 常公征 <changgz@yealink.com>
This commit is contained in:
Awadabang
2023-09-16 19:58:21 +08:00
committed by GitHub
parent b22ad50d59
commit cc21f5fae2
5 changed files with 103 additions and 10 deletions

View File

@@ -28,6 +28,16 @@ func DupReadCloser(reader io.ReadCloser) (io.ReadCloser, io.ReadCloser) {
return io.NopCloser(tee), io.NopCloser(&buf)
}
// LimitDupReadCloser returns two io.ReadCloser that read from the first will be written to the second.
// But the second io.ReadCloser is limited to up to n bytes.
// The first returned reader needs to be read first, because the content
// read from it will be written to the underlying buffer of the second reader.
func LimitDupReadCloser(reader io.ReadCloser, n int64) (io.ReadCloser, io.ReadCloser) {
var buf bytes.Buffer
tee := LimitTeeReader(reader, &buf, n)
return io.NopCloser(tee), io.NopCloser(&buf)
}
// KeepSpace customizes the reading functions to keep leading and tailing spaces.
func KeepSpace() TextReadOption {
return func(o *textReadOptions) {