/* default output stream is stdout */
outs->stream = stdout;
- /* --etag-save */
- etag_save = &per->etag_save;
- etag_save->stream = stdout;
-
- if(config->etag_save_file) {
- /* open file for output: */
- if(strcmp(config->etag_save_file, "-")) {
- FILE *newfile = fopen(config->etag_save_file, "wb");
- if(!newfile) {
- warnf(
- config->global,
- "Failed to open %s\n", config->etag_save_file);
-
- result = CURLE_WRITE_ERROR;
- break;
- }
- else {
- etag_save->filename = config->etag_save_file;
- etag_save->s_isreg = TRUE;
- etag_save->fopened = TRUE;
- etag_save->stream = newfile;
- }
- }
- else {
- /* always use binary mode for protocol header output */
- set_binmode(etag_save->stream);
- }
- }
-
/* --etag-compare */
if(config->etag_compare_file) {
char *etag_from_file = NULL;
/* open file for reading: */
FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
- if(!file) {
+ if(!file && !config->etag_save_file) {
errorf(config->global,
"Failed to open %s\n", config->etag_compare_file);
result = CURLE_READ_ERROR;
}
}
+ /* --etag-save */
+ etag_save = &per->etag_save;
+ etag_save->stream = stdout;
+
+ if(config->etag_save_file) {
+ /* open file for output: */
+ if(strcmp(config->etag_save_file, "-")) {
+ FILE *newfile = fopen(config->etag_save_file, "wb");
+ if(!newfile) {
+ warnf(
+ config->global,
+ "Failed to open %s\n", config->etag_save_file);
+
+ result = CURLE_WRITE_ERROR;
+ break;
+ }
+ else {
+ etag_save->filename = config->etag_save_file;
+ etag_save->s_isreg = TRUE;
+ etag_save->fopened = TRUE;
+ etag_save->stream = newfile;
+ }
+ }
+ else {
+ /* always use binary mode for protocol header output */
+ set_binmode(etag_save->stream);
+ }
+ }
+
if(metalink) {
/* For Metalink download, use name in Metalink file as
filename. */
--- /dev/null
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
+ETag: "21025-dc7-11111"
+Accept-Ranges: bytes
+Content-Length: 0
+Connection: close
+Content-Type: text/html
+Funny-head: yesyes
+
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+Both --etag-compare and -save store new Etag using non-existing file
+</name>
+<command>
+http://%HOSTIP:%HTTPPORT/344 --etag-compare log/etag344 --etag-save log/etag344
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET /344 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+If-None-Match: ""\r
+\r
+</protocol>
+<file name="log/etag344">
+21025-dc7-11111
+</file>
+</verify>
+</testcase>
--- /dev/null
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
+ETag: "21025-dc7-11111"
+Accept-Ranges: bytes
+Content-Length: 0
+Connection: close
+Content-Type: text/html
+Funny-head: yesyes
+
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+Both --etag-compare and -save store new Etag using one pre-existing file
+</name>
+<file name="log/etag345">
+21025-dc7-39462498
+</file>
+<command>
+http://%HOSTIP:%HTTPPORT/345 --etag-compare log/etag345 --etag-save log/etag345
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET /345 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+If-None-Match: "21025-dc7-39462498"\r
+\r
+</protocol>
+<file name="log/etag345">
+21025-dc7-11111
+</file>
+</verify>
+</testcase>