Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: allow overriding timecond with custom header
With CURLOPT_TIMECONDITION set, a header is automatically added (e.g. If-Modified-Since). Allow this to be replaced or suppressed with CURLOPT_HTTPHEADER. Closes curl#4103
- Loading branch information
Peter Simonyi
committed
Jul 11, 2019
1 parent
ac3d19a
commit 77c4ac5
Showing
7 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<testcase> | ||
<info> | ||
<keywords> | ||
HTTP | ||
HTTP GET | ||
HTTP replaced headers | ||
CURLOPT_TIMECONDITION | ||
If-Modified-Since | ||
</keywords> | ||
</info> | ||
|
||
# Server-side | ||
<reply> | ||
<data nocheck="yes"> | ||
HTTP/1.1 304 Not Modified | ||
Date: Thu, 11 Jul 2019 02:26:59 GMT | ||
Server: test-server/swsclose | ||
|
||
</data> | ||
</reply> | ||
# Client-side | ||
<client> | ||
<server> | ||
http | ||
</server> | ||
<name> | ||
HTTP custom header overrides CURLOPT_TIMECONDITION | ||
</name> | ||
<tool> | ||
lib1593 | ||
</tool> | ||
<command> | ||
http://%HOSTIP:%HTTPPORT/1593 | ||
</command> | ||
</client> | ||
|
||
<verify> | ||
<strip> | ||
^User-Agent:.* | ||
</strip> | ||
# Note here the lack of If-Modified-Since | ||
<protocol> | ||
GET /1593 HTTP/1.1 | ||
Host: %HOSTIP:%HTTPPORT | ||
Accept: */* | ||
|
||
</protocol> | ||
</verify> | ||
</testcase> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*************************************************************************** | ||
* _ _ ____ _ | ||
* Project ___| | | | _ \| | | ||
* / __| | | | |_) | | | ||
* | (__| |_| | _ <| |___ | ||
* \___|\___/|_| \_\_____| | ||
* | ||
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. | ||
* | ||
* 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. | ||
* | ||
***************************************************************************/ | ||
|
||
/* Test suppressing the If-Modified-Since header */ | ||
|
||
#include "test.h" | ||
|
||
#include "memdebug.h" | ||
|
||
int test(char *URL) | ||
{ | ||
long unmet; | ||
CURL *curl = NULL; | ||
int res = 0; | ||
|
||
global_init(CURL_GLOBAL_ALL); | ||
|
||
easy_init(curl); | ||
|
||
easy_setopt(curl, CURLOPT_URL, URL); | ||
easy_setopt(curl, CURLOPT_TIMECONDITION, (long)CURL_TIMECOND_IFMODSINCE); | ||
/* Some TIMEVALUE; it doesn't matter. */ | ||
easy_setopt(curl, CURLOPT_TIMEVALUE, 1566210680L); | ||
|
||
struct curl_slist *header = NULL; | ||
header = curl_slist_append(header, "If-Modified-Since:"); | ||
|
||
easy_setopt(curl, CURLOPT_HTTPHEADER, header); | ||
|
||
res = curl_easy_perform(curl); | ||
if(res) | ||
goto test_cleanup; | ||
|
||
/* Confirm that the condition checking still worked, even though we | ||
* suppressed the actual header. | ||
* The server returns 304, which means the condition is "unmet". | ||
*/ | ||
|
||
res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet); | ||
if(res) | ||
goto test_cleanup; | ||
|
||
if(unmet != 1L) { | ||
res = TEST_ERR_FAILURE; | ||
goto test_cleanup; | ||
} | ||
|
||
test_cleanup: | ||
|
||
/* always cleanup */ | ||
curl_easy_cleanup(curl); | ||
curl_slist_free_all(header); | ||
curl_global_cleanup(); | ||
|
||
return res; | ||
} |