diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2021-02-16 21:53:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-16 21:53:53 +0100 |
commit | 3cd0862fbb17abb02d43e538e41819e22ffd512a (patch) | |
tree | bf5be9dabdbc55a466228f676cdc8cb378e146a9 /streaming.go | |
parent | Added Protocol() as a replacement of hardcoded strHTTP11 (#969) (diff) | |
download | fasthttp-3cd0862fbb17abb02d43e538e41819e22ffd512a.tar.gz fasthttp-3cd0862fbb17abb02d43e538e41819e22ffd512a.tar.bz2 fasthttp-3cd0862fbb17abb02d43e538e41819e22ffd512a.zip |
- Allow DisablePreParseMultipartForm in combination with
StreamRequestBody.
- Support streaming into MultipartForm instead of reading the whole body
first.
- Support calling ctx.PostBody() when streaming is enabled.
Diffstat (limited to 'streaming.go')
-rw-r--r-- | streaming.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/streaming.go b/streaming.go index a6ad0a9..39000a2 100644 --- a/streaming.go +++ b/streaming.go @@ -45,7 +45,12 @@ func (rs *requestStream) Read(p []byte) (int, error) { } var n int var err error - if int(rs.prefetchedBytes.Size()) > rs.totalBytesRead { + prefetchedSize := int(rs.prefetchedBytes.Size()) + if prefetchedSize > rs.totalBytesRead { + left := prefetchedSize - rs.totalBytesRead + if len(p) > left { + p = p[:left] + } n, err := rs.prefetchedBytes.Read(p) rs.totalBytesRead += n if n == rs.contentLength { @@ -53,6 +58,10 @@ func (rs *requestStream) Read(p []byte) (int, error) { } return n, err } else { + left := rs.contentLength - rs.totalBytesRead + if len(p) > left { + p = p[:left] + } n, err = rs.reader.Read(p) rs.totalBytesRead += n if err != nil { |