mirror of
https://github.com/Ed1s0nZ/PrivHunterAI.git
synced 2026-10-24 16:44:26 +00:00
32 lines
685 B
Go
32 lines
685 B
Go
package scanner
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"errors"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
func decodeBody(body []byte, encoding string) ([]byte, error) {
|
|
if len(body) > maxBody {
|
|
return nil, errors.New("body too large")
|
|
}
|
|
if strings.EqualFold(encoding, "gzip") {
|
|
reader, e := gzip.NewReader(bytes.NewReader(body))
|
|
if e != nil {
|
|
return nil, e
|
|
}
|
|
defer reader.Close()
|
|
output, e := io.ReadAll(io.LimitReader(reader, maxBody+1))
|
|
if e != nil || len(output) > maxBody {
|
|
return nil, errors.New("decoded body too large or invalid")
|
|
}
|
|
return output, nil
|
|
}
|
|
if encoding != "" && encoding != "identity" {
|
|
return nil, errors.New("unsupported encoding")
|
|
}
|
|
return body, nil
|
|
}
|