lib1593.c 2.2 KB

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