mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-15 16:47:38 +08:00
fix(maxreader): treat non-positive limits as unlimited
This commit is contained in:
parent
91c50536c4
commit
e6ff0fa6b9
2 changed files with 10 additions and 23 deletions
|
|
@ -31,13 +31,13 @@ type maxBytesReader struct {
|
|||
// 但在读取的字节数超过 n 后会返回 ErrBodyTooLarge 错误.
|
||||
//
|
||||
// 如果 r 为 nil, 会 panic.
|
||||
// 如果 n 小于 0, 则读取不受限制, 直接返回原始的 r.
|
||||
// 如果 n 小于等于 0, 则读取不受限制, 直接返回原始的 r.
|
||||
func NewMaxBytesReader(r io.ReadCloser, n int64) io.ReadCloser {
|
||||
if r == nil {
|
||||
panic("NewMaxBytesReader called with a nil reader")
|
||||
}
|
||||
// 如果限制为负数, 意味着不限制, 直接返回原始的 ReadCloser.
|
||||
if n < 0 {
|
||||
// 如果限制为非正数, 意味着不限制, 直接返回原始的 ReadCloser.
|
||||
if n <= 0 {
|
||||
return r
|
||||
}
|
||||
return &maxBytesReader{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue