2
0

lib1532.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2021, 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. #include "test.h"
  23. #include "memdebug.h"
  24. /* Test CURLINFO_RESPONSE_CODE */
  25. int test(char *URL)
  26. {
  27. CURL *curl;
  28. long httpcode;
  29. int res = CURLE_OK;
  30. global_init(CURL_GLOBAL_ALL);
  31. easy_init(curl);
  32. easy_setopt(curl, CURLOPT_URL, URL);
  33. res = curl_easy_perform(curl);
  34. if(res) {
  35. fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n",
  36. __FILE__, __LINE__, res, curl_easy_strerror(res));
  37. goto test_cleanup;
  38. }
  39. res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpcode);
  40. if(res) {
  41. fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
  42. __FILE__, __LINE__, res, curl_easy_strerror(res));
  43. goto test_cleanup;
  44. }
  45. if(httpcode != 200) {
  46. fprintf(stderr, "%s:%d unexpected response code %ld\n",
  47. __FILE__, __LINE__, httpcode);
  48. res = CURLE_HTTP_RETURNED_ERROR;
  49. goto test_cleanup;
  50. }
  51. /* Test for a regression of github bug 1017 (response code does not reset) */
  52. curl_easy_reset(curl);
  53. res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpcode);
  54. if(res) {
  55. fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
  56. __FILE__, __LINE__, res, curl_easy_strerror(res));
  57. goto test_cleanup;
  58. }
  59. if(httpcode) {
  60. fprintf(stderr, "%s:%d curl_easy_reset failed to zero the response code\n"
  61. "possible regression of github bug 1017\n", __FILE__, __LINE__);
  62. res = CURLE_HTTP_RETURNED_ERROR;
  63. goto test_cleanup;
  64. }
  65. test_cleanup:
  66. curl_easy_cleanup(curl);
  67. curl_global_cleanup();
  68. return res;
  69. }