1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

getinfo: reset retry-after value in initinfo

- 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
This commit is contained in:
Nicolas Sterchele 2020-07-10 20:05:21 +02:00 committed by Daniel Stenberg
parent 0c6112a139
commit 0b85969226
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
5 changed files with 130 additions and 2 deletions

View 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;

View File

@ -225,4 +225,4 @@ test2080 \
test2100 \
\
test3000 test3001 \
test3002 test3003 test3004 test3005 test3006 test3007
test3002 test3003 test3004 test3005 test3006 test3007 test3010

57
tests/data/test3010 Normal file
View File

@ -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>

View 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)

66
tests/libtest/lib3010.c Normal file
View File

@ -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;
}