xref: /curl/tests/libtest/lib1593.c (revision 25cbc2f7)
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  * SPDX-License-Identifier: curl
22  *
23  ***************************************************************************/
24 
25 /* Test suppressing the If-Modified-Since header */
26 
27 #include "test.h"
28 
29 #include "memdebug.h"
30 
test(char * URL)31 CURLcode test(char *URL)
32 {
33   struct curl_slist *header = NULL;
34   long unmet;
35   CURL *curl = NULL;
36   CURLcode res = CURLE_OK;
37 
38   global_init(CURL_GLOBAL_ALL);
39 
40   easy_init(curl);
41 
42   easy_setopt(curl, CURLOPT_URL, URL);
43   easy_setopt(curl, CURLOPT_TIMECONDITION, (long)CURL_TIMECOND_IFMODSINCE);
44   /* Some TIMEVALUE; it doesn't matter. */
45   easy_setopt(curl, CURLOPT_TIMEVALUE, 1566210680L);
46 
47   header = curl_slist_append(NULL, "If-Modified-Since:");
48   if(!header) {
49     res = TEST_ERR_MAJOR_BAD;
50     goto test_cleanup;
51   }
52 
53   easy_setopt(curl, CURLOPT_HTTPHEADER, header);
54 
55   res = curl_easy_perform(curl);
56   if(res)
57     goto test_cleanup;
58 
59   /* Confirm that the condition checking still worked, even though we
60    * suppressed the actual header.
61    * The server returns 304, which means the condition is "unmet".
62    */
63 
64   res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
65   if(res)
66     goto test_cleanup;
67 
68   if(unmet != 1L) {
69     res = TEST_ERR_FAILURE;
70     goto test_cleanup;
71   }
72 
73 test_cleanup:
74 
75   /* always cleanup */
76   curl_easy_cleanup(curl);
77   curl_slist_free_all(header);
78   curl_global_cleanup();
79 
80   return res;
81 }
82