fix: upload_manager write header in time (#1471)

Signed-off-by: bigerous <bigerous@qq.com>
This commit is contained in:
cuidajun 2022-07-19 19:40:20 +08:00 committed by Gaius
parent cd0ecceacf
commit abec6d3a84
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
1 changed files with 4 additions and 2 deletions

View File

@ -192,8 +192,6 @@ func (um *uploadManager) getDownload(ctx *gin.Context) {
return
}
// Add header "Content-Length" to avoid chunked body in http client.
ctx.Header(headers.ContentLength, fmt.Sprintf("%d", rg[0].Length))
reader, closer, err := um.storageManager.ReadPiece(ctx,
&storage.ReadPieceRequest{
PeerTaskMetadata: storage.PeerTaskMetadata{
@ -212,8 +210,12 @@ func (um *uploadManager) getDownload(ctx *gin.Context) {
}
defer closer.Close()
// Add header "Content-Length" to avoid chunked body in http client.
ctx.Header(headers.ContentLength, fmt.Sprintf("%d", rg[0].Length))
// write header immediately, prevent client disconnecting after limiter.Wait() due to response header timeout
ctx.Writer.WriteHeaderNow()
ctx.Writer.Flush()
if um.Limiter != nil {
if err = um.Limiter.WaitN(ctx, int(rg[0].Length)); err != nil {