mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-02-03 08:51:11 +08:00
fix limitMaxSizeReader non use body close & fix mergeCtx Value
This commit is contained in:
parent
cb86cb935a
commit
49508b49c1
2 changed files with 14 additions and 8 deletions
12
context.go
12
context.go
|
|
@ -456,6 +456,12 @@ func (c *Context) GetReqBodyFull() ([]byte, error) {
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
limitBytesReader = c.Request.Body
|
limitBytesReader = c.Request.Body
|
||||||
|
defer func() {
|
||||||
|
err := limitBytesReader.Close()
|
||||||
|
if err != nil {
|
||||||
|
c.AddError(fmt.Errorf("failed to close request body: %w", err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := copyb.ReadAll(limitBytesReader)
|
data, err := copyb.ReadAll(limitBytesReader)
|
||||||
|
|
@ -484,6 +490,12 @@ func (c *Context) GetReqBodyBuffer() (*bytes.Buffer, error) {
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
limitBytesReader = c.Request.Body
|
limitBytesReader = c.Request.Body
|
||||||
|
defer func() {
|
||||||
|
err := limitBytesReader.Close()
|
||||||
|
if err != nil {
|
||||||
|
c.AddError(fmt.Errorf("failed to close request body: %w", err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := copyb.ReadAll(limitBytesReader)
|
data, err := copyb.ReadAll(limitBytesReader)
|
||||||
|
|
|
||||||
10
mergectx.go
10
mergectx.go
|
|
@ -69,15 +69,9 @@ func MergeCtx(parents ...context.Context) (ctx context.Context, cancel context.C
|
||||||
return mc, mc.cancel
|
return mc, mc.cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value 实现了 context.Context 的 Value 方法.
|
// Value 返回当前Ctx Value
|
||||||
// 它会按顺序遍历所有父 context, 并返回第一个找到的非 nil 值.
|
|
||||||
func (mc *mergedContext) Value(key any) any {
|
func (mc *mergedContext) Value(key any) any {
|
||||||
for _, p := range mc.parents {
|
return mc.Context.Value(key)
|
||||||
if v := p.Value(key); v != nil {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deadline 实现了 context.Context 的 Deadline 方法.
|
// Deadline 实现了 context.Context 的 Deadline 方法.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue