Skip to content

Commit

Permalink
fixed mget when the server returns chunked content
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Jan 3, 2024
1 parent 0476910 commit 0a01bc3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
@@ -1 +1 @@
'2.2.6595'
'2.2.6596'
20 changes: 7 additions & 13 deletions src/net/mormot.net.client.pas
Expand Up @@ -1697,19 +1697,13 @@ procedure THttpClientSocket.RequestInternal(
not HttpMethodWithNoBody(ctxt.method) then
// HEAD or status 100..109,204,304 -> no body (RFC 2616 section 4.3)
begin
if ctxt.OutStream <> nil then
begin
if (Http.ContentLength > 0) and
(ctxt.Status in [HTTP_SUCCESS, HTTP_PARTIALCONTENT]) then
begin
if ctxt.OutStream.InheritsFrom(TStreamRedirect) then
TStreamRedirect(ctxt.OutStream).ExpectedSize :=
fRangeStart + Http.ContentLength;
GetBody(ctxt.OutStream)
end;
end
else
GetBody(nil);
if (ctxt.OutStream <> nil) and
(Http.ContentLength > 0) and
(ctxt.Status in [HTTP_SUCCESS, HTTP_PARTIALCONTENT]) and
ctxt.OutStream.InheritsFrom(TStreamRedirect) then
TStreamRedirect(ctxt.OutStream).ExpectedSize :=
fRangeStart + Http.ContentLength; // we know the size
GetBody(ctxt.OutStream); // retrieve whole response body
end;
// successfully sent -> reset some fields for the next request
if ctxt.Status in [HTTP_SUCCESS, HTTP_PARTIALCONTENT] then
Expand Down
2 changes: 1 addition & 1 deletion src/net/mormot.net.http.pas
Expand Up @@ -2234,7 +2234,7 @@ procedure THttpSocket.GetBody(DestStream: TStream);
if DestStream <> nil then
begin
if length({%H-}chunk) < len32 then
SetString(chunk, nil, len32 + len32 shr 3); // + shr 3 to avoid realloc
SetString(chunk, nil, len32 + len32 shr 3); // +shr 3 to avoid realloc
SockInRead(pointer(chunk), len32);
DestStream.WriteBuffer(pointer(chunk)^, len32);
end
Expand Down

0 comments on commit 0a01bc3

Please sign in to comment.