lib1532.c (2788B)
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 #include "first.h" 25 26 #include "memdebug.h" 27 28 /* Test CURLINFO_RESPONSE_CODE */ 29 30 static CURLcode test_lib1532(char *URL) 31 { 32 CURL *curl; 33 long httpcode; 34 CURLcode res = CURLE_OK; 35 36 global_init(CURL_GLOBAL_ALL); 37 38 easy_init(curl); 39 40 easy_setopt(curl, CURLOPT_URL, URL); 41 42 res = curl_easy_perform(curl); 43 if(res) { 44 curl_mfprintf(stderr, 45 "%s:%d curl_easy_perform() failed with code %d (%s)\n", 46 __FILE__, __LINE__, res, curl_easy_strerror(res)); 47 goto test_cleanup; 48 } 49 50 res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpcode); 51 if(res) { 52 curl_mfprintf(stderr, 53 "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", 54 __FILE__, __LINE__, res, curl_easy_strerror(res)); 55 goto test_cleanup; 56 } 57 if(httpcode != 200) { 58 curl_mfprintf(stderr, "%s:%d unexpected response code %ld\n", 59 __FILE__, __LINE__, httpcode); 60 res = CURLE_HTTP_RETURNED_ERROR; 61 goto test_cleanup; 62 } 63 64 /* Test for a regression of github bug 1017 (response code does not reset) */ 65 curl_easy_reset(curl); 66 67 res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpcode); 68 if(res) { 69 curl_mfprintf(stderr, 70 "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", 71 __FILE__, __LINE__, res, curl_easy_strerror(res)); 72 goto test_cleanup; 73 } 74 if(httpcode) { 75 curl_mfprintf(stderr, 76 "%s:%d curl_easy_reset failed to zero the response code\n" 77 "possible regression of github bug 1017\n", 78 __FILE__, __LINE__); 79 res = CURLE_HTTP_RETURNED_ERROR; 80 goto test_cleanup; 81 } 82 83 test_cleanup: 84 curl_easy_cleanup(curl); 85 curl_global_cleanup(); 86 return res; 87 }