lib1518.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 inspired by github issue 3340 */
  25. int test(char *URL)
  26. {
  27. CURL *curl;
  28. CURLcode res = CURLE_OK;
  29. long curlResponseCode;
  30. long curlRedirectCount;
  31. char *effectiveUrl = NULL;
  32. char *redirectUrl = NULL;
  33. curl = curl_easy_init();
  34. if(!curl) {
  35. fprintf(stderr, "curl_easy_init() failed\n");
  36. curl_global_cleanup();
  37. return TEST_ERR_MAJOR_BAD;
  38. }
  39. test_setopt(curl, CURLOPT_URL, URL);
  40. /* just to make it explicit and visible in this test: */
  41. test_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
  42. /* Perform the request, res will get the return code */
  43. res = curl_easy_perform(curl);
  44. curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curlResponseCode);
  45. curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount);
  46. curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl);
  47. curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectUrl);
  48. printf("res %d\n"
  49. "status %d\n"
  50. "redirects %d\n"
  51. "effectiveurl %s\n"
  52. "redirecturl %s\n",
  53. (int)res,
  54. (int)curlResponseCode,
  55. (int)curlRedirectCount,
  56. effectiveUrl,
  57. redirectUrl);
  58. test_cleanup:
  59. /* always cleanup */
  60. curl_easy_cleanup(curl);
  61. curl_global_cleanup();
  62. return res;
  63. }