Hi,

as reported at [0], the timecond session variable doesn't get reset before
performing a request, so CURLINFO_CONDITION_UNMET may report wrong values (ie
"1" when it should be "0") if eg the CURLOPT_TIMEVALUE option changes between
requests.

The attached test case does two requests: the first with TIMEVALUE set into the
future so CURLINFO_CONDITION_UNMET reports "1" after, the second with TIMEVALUE
in the past, but CURLINFO_CONDITION_UNMET still reports "1". If the first
request is commented out the CURLINFO_CONDITION_UNMET of the remaining request
reports correctly "0".

Also attached is the patch that should fix this.

Cheers

[0] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=705783

-- 
perl -E '$_=q;$/= @{[@_]};and s;\S+;<inidehG ordnasselA>;eg;say~~reverse'
#include <assert.h>
#include <curl/curl.h>

size_t data(void *buf, size_t size, size_t nmemb, void *p) {
	return size * nmemb;
}

void perform(CURL* curl, const long ts, const long expected) {
	curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
	curl_easy_setopt(curl, CURLOPT_TIMEVALUE, ts);

	CURLcode success = curl_easy_perform(curl);
	assert(success == CURLE_OK);

	long unmet = 0;
	curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);

	assert(unmet == expected);
}

int main(int argc, char *argv[]) {
	CURL *curl = curl_easy_init();

	curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se";);
	/* curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); */
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, data);

	perform(curl, 1566210680, 1); /* expect UNMET == 1 */
	perform(curl, 1, 0);          /* expect UNMET == 0 */

	return 0;
}
From b4e6a3a974c24ca2aee77150a633ac85e807a3e7 Mon Sep 17 00:00:00 2001
From: Alessandro Ghedini <[email protected]>
Date: Sat, 20 Apr 2013 12:09:55 +0200
Subject: [PATCH] getinfo.c: reset timecond when clearing session-info
 variables

Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=705783
Reported-by: Ludovico Cavedon <[email protected]>
---
 lib/getinfo.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/getinfo.c b/lib/getinfo.c
index 74e5b08..101ac90 100644
--- a/lib/getinfo.c
+++ b/lib/getinfo.c
@@ -55,6 +55,7 @@ CURLcode Curl_initinfo(struct SessionHandle *data)
   info->httpcode = 0;
   info->httpversion=0;
   info->filetime=-1; /* -1 is an illegal time and thus means unknown */
+  info->timecond=0;
 
   if(info->contenttype)
     free(info->contenttype);
-- 
1.8.2.1

Attachment: signature.asc
Description: Digital signature

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to