lib1593.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /* Test suppressing the If-Modified-Since header */
  25. #include "test.h"
  26. #include "memdebug.h"
  27. int test(char *URL)
  28. {
  29. struct curl_slist *header = NULL;
  30. long unmet;
  31. CURL *curl = NULL;
  32. int res = 0;
  33. global_init(CURL_GLOBAL_ALL);
  34. easy_init(curl);
  35. easy_setopt(curl, CURLOPT_URL, URL);
  36. easy_setopt(curl, CURLOPT_TIMECONDITION, (long)CURL_TIMECOND_IFMODSINCE);
  37. /* Some TIMEVALUE; it doesn't matter. */
  38. easy_setopt(curl, CURLOPT_TIMEVALUE, 1566210680L);
  39. header = curl_slist_append(NULL, "If-Modified-Since:");
  40. if(!header) {
  41. res = TEST_ERR_MAJOR_BAD;
  42. goto test_cleanup;
  43. }
  44. easy_setopt(curl, CURLOPT_HTTPHEADER, header);
  45. res = curl_easy_perform(curl);
  46. if(res)
  47. goto test_cleanup;
  48. /* Confirm that the condition checking still worked, even though we
  49. * suppressed the actual header.
  50. * The server returns 304, which means the condition is "unmet".
  51. */
  52. res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
  53. if(res)
  54. goto test_cleanup;
  55. if(unmet != 1L) {
  56. res = TEST_ERR_FAILURE;
  57. goto test_cleanup;
  58. }
  59. test_cleanup:
  60. /* always cleanup */
  61. curl_easy_cleanup(curl);
  62. curl_slist_free_all(header);
  63. curl_global_cleanup();
  64. return res;
  65. }