• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2019, 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.haxx.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  ***************************************************************************/
22 
23 /* Test suppressing the If-Modified-Since header */
24 
25 #include "test.h"
26 
27 #include "memdebug.h"
28 
test(char * URL)29 int test(char *URL)
30 {
31   struct curl_slist *header = NULL;
32   long unmet;
33   CURL *curl = NULL;
34   int res = 0;
35 
36   global_init(CURL_GLOBAL_ALL);
37 
38   easy_init(curl);
39 
40   easy_setopt(curl, CURLOPT_URL, URL);
41   easy_setopt(curl, CURLOPT_TIMECONDITION, (long)CURL_TIMECOND_IFMODSINCE);
42   /* Some TIMEVALUE; it doesn't matter. */
43   easy_setopt(curl, CURLOPT_TIMEVALUE, 1566210680L);
44 
45   header = curl_slist_append(NULL, "If-Modified-Since:");
46   if(!header) {
47     res = TEST_ERR_MAJOR_BAD;
48     goto test_cleanup;
49   }
50 
51   easy_setopt(curl, CURLOPT_HTTPHEADER, header);
52 
53   res = curl_easy_perform(curl);
54   if(res)
55     goto test_cleanup;
56 
57   /* Confirm that the condition checking still worked, even though we
58    * suppressed the actual header.
59    * The server returns 304, which means the condition is "unmet".
60    */
61 
62   res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
63   if(res)
64     goto test_cleanup;
65 
66   if(unmet != 1L) {
67     res = TEST_ERR_FAILURE;
68     goto test_cleanup;
69   }
70 
71 test_cleanup:
72 
73   /* always cleanup */
74   curl_easy_cleanup(curl);
75   curl_slist_free_all(header);
76   curl_global_cleanup();
77 
78   return res;
79 }
80