]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
getinfo: reset retry-after value in initinfo
authorNicolas Sterchele <sterchelen@gmail.com>
Fri, 10 Jul 2020 18:05:21 +0000 (20:05 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 27 Jul 2020 10:15:44 +0000 (12:15 +0200)
- Avoid re-using retry_after value from preceding request
- Add libtest 3010 to verify

Reported-by: joey-l-us on github
Fixes #5661
Closes #5672

lib/getinfo.c
tests/data/Makefile.inc
tests/data/test3010 [new file with mode: 0644]
tests/libtest/Makefile.inc
tests/libtest/lib3010.c [new file with mode: 0644]

index 675a616f007ceb17ea77bd548a3d185305781353..82691dcc7118b26ae1f92a6483b7213f0e414127 100644 (file)
@@ -78,6 +78,7 @@ CURLcode Curl_initinfo(struct Curl_easy *data)
   info->conn_local_ip[0] = '\0';
   info->conn_primary_port = 0;
   info->conn_local_port = 0;
+  info->retry_after = 0;
 
   info->conn_scheme = 0;
   info->conn_protocol = 0;
index 667d7951a98d4ef140561f0e01a500c6033b8c4c..e5dfbfde4a323e83b095bfa38ae021c60ba9b159 100644 (file)
@@ -225,4 +225,4 @@ test2080 \
 test2100 \
 \
 test3000 test3001 \
-test3002 test3003 test3004 test3005 test3006 test3007
+test3002 test3003 test3004 test3005 test3006 test3007 test3010
diff --git a/tests/data/test3010 b/tests/data/test3010
new file mode 100644 (file)
index 0000000..1372a79
--- /dev/null
@@ -0,0 +1,57 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP Basic
+RETRY-AFTER
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.1 301 Moved Permanently
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Content-Length: 0
+Retry-After: 2
+Location: /30100002
+
+</data>
+<data2>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Content-Length: 0
+
+</data2>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+
+<name>
+HTTP retry-after reset
+</name>
+<tool>
+lib3010
+</tool>
+
+<command>
+%HOSTIP:%HTTPPORT/3010
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<stdout>
+Retry-After: 2
+Retry-After: 0
+</stdout>
+</verify>
+</testcase>
index bc193bd9d719e4dd373923af405ddadb2fb4b215..8ad7dc4e60348e39c15c13545dfb166c154864d7 100644 (file)
@@ -59,7 +59,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect                \
  lib1558 lib1559 lib1560 lib1564 lib1565 \
  lib1591 lib1592 lib1593 lib1594 lib1596 \
  lib1900 lib1905 lib1906 lib1907 lib1908 lib1910 \
- lib2033
+ lib2033 lib3010
 
 chkdecimalpoint_SOURCES = chkdecimalpoint.c ../../lib/mprintf.c \
  ../../lib/curl_ctype.c  ../../lib/dynbuf.c ../../lib/strdup.c
@@ -649,3 +649,7 @@ lib1910_CPPFLAGS = $(AM_CPPFLAGS)
 lib2033_SOURCES = libntlmconnect.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib2033_LDADD = $(TESTUTIL_LIBS)
 lib2033_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_PIPELINING
+
+lib3010_SOURCES = lib3010.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
+lib3010_LDADD = $(TESTUTIL_LIBS)
+lib3010_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/tests/libtest/lib3010.c b/tests/libtest/lib3010.c
new file mode 100644 (file)
index 0000000..9c24b2f
--- /dev/null
@@ -0,0 +1,66 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2020 - 2020, Nicolas Sterchele, <nicolas@sterchelen.net>
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "memdebug.h"
+
+int test(char *URL)
+{
+  CURLcode ret = CURLE_OK;
+  CURL *curl = NULL;
+  curl_off_t retry_after;
+  char *follow_url = NULL;
+
+  curl_global_init(CURL_GLOBAL_ALL);
+  curl = curl_easy_init();
+
+  if(curl) {
+    curl_easy_setopt(curl, CURLOPT_URL, URL);
+    ret = curl_easy_perform(curl);
+    if(ret) {
+      fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n",
+          __FILE__, __LINE__, ret, curl_easy_strerror(ret));
+      goto test_cleanup;
+    }
+    curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &follow_url);
+    curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &retry_after);
+    printf("Retry-After: %" CURL_FORMAT_CURL_OFF_T "\n", retry_after);
+    curl_easy_setopt(curl, CURLOPT_URL, follow_url);
+    ret = curl_easy_perform(curl);
+    if(ret) {
+      fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n",
+          __FILE__, __LINE__, ret, curl_easy_strerror(ret));
+      goto test_cleanup;
+    }
+
+    curl_easy_reset(curl);
+    curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &retry_after);
+    printf("Retry-After: %" CURL_FORMAT_CURL_OFF_T "\n", retry_after);
+  }
+
+test_cleanup:
+  curl_easy_cleanup(curl);
+  curl_global_cleanup();
+
+  return ret;
+}
+