aboutsummaryrefslogtreecommitdiff
path: root/streaming.go
diff options
context:
space:
mode:
authorGravatar Erik Dubbelboer <erik@dubbelboer.com> 2021-02-16 21:53:53 +0100
committerGravatar GitHub <noreply@github.com> 2021-02-16 21:53:53 +0100
commit3cd0862fbb17abb02d43e538e41819e22ffd512a (patch)
treebf5be9dabdbc55a466228f676cdc8cb378e146a9 /streaming.go
parentAdded Protocol() as a replacement of hardcoded strHTTP11 (#969) (diff)
downloadfasthttp-3cd0862fbb17abb02d43e538e41819e22ffd512a.tar.gz
fasthttp-3cd0862fbb17abb02d43e538e41819e22ffd512a.tar.bz2
fasthttp-3cd0862fbb17abb02d43e538e41819e22ffd512a.zip
Streaming fixes (#970)v1.21.0
- 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.go11
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 {