diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-10-30 13:10:42 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-10-30 13:10:42 -0600 |
commit | 3f1973b621ad10e783955244d0d9f39176feda45 (patch) | |
tree | 85ef65aa41db4ff6d5ca6585d8147f9e44796047 /spartan/request.go | |
parent | 87189fafa7134f70dcdd51f1d508686573a91979 (diff) |
set request body in spartan.ParseRequest
Diffstat (limited to 'spartan/request.go')
-rw-r--r-- | spartan/request.go | 22 |
1 files changed, 1 insertions, 21 deletions
diff --git a/spartan/request.go b/spartan/request.go index c88a20b..36dd225 100644 --- a/spartan/request.go +++ b/spartan/request.go @@ -2,7 +2,6 @@ package spartan import ( "bufio" - "bytes" "errors" "io" "net/url" @@ -59,6 +58,7 @@ func ParseRequest(rdr io.Reader) (*types.Request, int, error) { Path: path, RawPath: path, }, + Meta: &io.LimitedReader{R: bufrdr, N: int64(contentlen)}, }, contentlen, nil } @@ -81,23 +81,3 @@ func GetRequestBody(request *types.Request) io.Reader { } return nil } - -// SetRequestBody adds an io.Reader as a request body. -// -// It is for use in clients, preparing the request to be sent. -// -// This function will read the entire contents into memory unless -// the reader is already an *io.LimitedReader. -func SetRequestBody(request *types.Request, body io.Reader) error { - if rdr, ok := body.(*io.LimitedReader); ok { - request.Meta = rdr - return nil - } - - buf, err := io.ReadAll(body) - if err != nil { - return err - } - request.Meta = io.LimitReader(bytes.NewBuffer(buf), int64(len(buf))) - return nil -} |