8000 tool_operate: keep failed partial download for retry auto-resume by jay · Pull Request #18665 · curl/curl · GitHub
[go: up one dir, main page]

Skip to content

Conversation

jay
Copy link
Member
@jay jay commented Sep 21, 2025
  • Keep data from a failed download instead of discarding it on retry in some limited cases when we know it's ok (currently only HTTP 200/206).

Prior to this change on failed transfer the tool truncated any outfile data written before retrying the transfer. This change adds an exception for HTTP downloads when the user requested auto-resume, because in that case we can keep the outfile data and resume from the new position.

Reported-by: tkzv@users.noreply.github.com

Fixes #18035
Closes #xxxx


This PR is a resurrection of #15333 which stalled

(config->httpreq == TOOL_HTTPREQ_UNSPEC ||
config->httpreq == TOOL_HTTPREQ_GET) &&
(!config->customrequest || !strcmp(config->customrequest, "GET")) &&
!config->use_ascii && !per->uploadfile &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use_ascii is documented to not have an effect on HTTP transfers. Why do we need to check that for resuming a retry?

Can uploadfile really be set if httpreq is GET or UNSPEC?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use_ascii is documented to not have an effect on HTTP transfers. Why do we need to check that for resuming a retry?

I'll remove the check, after checking the code I don't think it's needed.

Note --use-ascii is documented for FTP and LDAP but from what I can see it sets CURLOPT_TRANSFERTEXT which may apply to more protocols in the library. And in the tool it looks like it leaves stdout in text mode no matter the protocol:

curl/src/tool_operate.c

Lines 1292 to 1297 in 11b9912

if((!per->outfile || !strcmp(per->outfile, "-")) &&
!config->use_ascii) {
/* We get the output to stdout and we have not got the ASCII/text flag,
then set stdout to be binary */
CURLX_SET_BINMODE(stdout);
}

Is this useful for Windows for other protocols? Like maybe HTTP something someone wants it converted to CRLF?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can uploadfile really be set if httpreq is GET or UNSPEC?

This I don't know for certain and I'd prefer to leave it for posterity.


if((scheme == proto_http || scheme == proto_https) &&
method && !strcmp(method, "GET") &&
response == (config->resume_from ? 206 : 200)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the server to also send Accept-Ranges: bytes to signal it accepts range requests (using byte ranges).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the server to also send Accept-Ranges: bytes to signal it accepts range requests (using byte ranges).

Do most servers do this in practice? I'll add a check for it when response code is 200 (and not 206).

@jay
Copy link
Member Author
jay commented Sep 27, 2025

The CI complexity check is failing. Any advice for this? There's not much that could be considered complex except the conditional in the if statement, which I could move into a separate function but I'd prefer to leave it as is.

@jay
Copy link
Member Author
jay commented Sep 27, 2025

I am trying a commit that moves the conditional to a separate function, but in my opinion it would be better inline

@jay
Copy link
Member Author
jay commented Oct 7, 2025

Does anyone want to give this another look? I'd like to get it in before the feature freeze this weekend.

- Keep data from a failed download instead of discarding it on retry in
  some limited cases when we know it's ok (currently only HTTP 200/206).

Prior to this change on failed transfer the tool truncated any outfile
data written before retrying the transfer. This change adds an exception
for HTTP downloads when the user requested auto-resume, because in that
case we can keep the outfile data and resume from the new position.

Reported-by: tkzv@users.noreply.github.com

Fixes curl#18035
Closes #xxxx
@jay jay force-pushed the better_auto_resume2 branch from 777d1d0 to a7ef4fa Compare October 8, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

--retry ignores --continue-at for the latest file
2 participants
0