доза: ограничьте прочитанный размер тела
This commit is contained in:
parent
7f7d10aeee
commit
e16920be5f
1 changed files with 6 additions and 4 deletions
|
|
@ -13,6 +13,8 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const MAX_SIZE = 2 ^ 16 // 65kb
|
||||
|
||||
func main() {
|
||||
proxy := &httputil.ReverseProxy{
|
||||
Rewrite: func(r *httputil.ProxyRequest) {
|
||||
|
|
@ -42,12 +44,12 @@ func main() {
|
|||
switch r.Header.Get("Content-Encoding") {
|
||||
case "gzip":
|
||||
reader, _ := gzip.NewReader(r.Body)
|
||||
data, _ = io.ReadAll(reader)
|
||||
r.Body.Close()
|
||||
data, _ = io.ReadAll(io.LimitReader(reader, MAX_SIZE))
|
||||
reader.Close()
|
||||
default:
|
||||
data, _ = io.ReadAll(r.Body)
|
||||
r.Body.Close()
|
||||
data, _ = io.ReadAll(io.LimitReader(r.Body, MAX_SIZE))
|
||||
}
|
||||
r.Body.Close()
|
||||
|
||||
// Rewrite 30x redirect location
|
||||
locHeader := r.Header.Get("Location")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue