curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: File overwritten with HTTP/1.1 304 Not Modified

From: Daniel Stenberg via curl-users <>
Date: Tue, 3 Sep 2019 11:10:25 +0200 (CEST)

On Sat, 31 Aug 2019, Paul Gilmartin via curl-users wrote:

> *however* my --output file is overwritten with an empty file.
> I'd prefer that this not happen.
> Is there a combination of options that preserves the file in case of 304?
> Should I consider this a bug?
> I believe an earlier release of curl on Raspberry Pi did not overwrite.

I believe we may have at some point changed the behavior slightly on writing a
zero byte body - but I can't remember why. I don't think this is 304 specific
but works the same no matter which response code.

The question of course remains what the "correct" behavior is. A zero byte
file could very well be interpreted as the correct way to represent a zero
byte response body...

> I understand that in case of some errors, such as 404, the user prefers to
> receive the file.

1. curl will of course save the response body for any response code, but 304s
are special as they are defined to never have a body.

2. --fail will make curl not save the 404 response body

  / | Get the best commercial curl support there is - from me
                   | Private help, bug fixes, support, ports, new features
Received on 2019-09-03