Browse Source

Check for correct HTTP response code.

Beyond authentication failure, there are other conditions for which
Libcurl does not automatically return an error. E.g., if the server
replies with a 404 Not Found, from Libcurl's point of view that is still
a success (the request went through and a reply was received). So we
need to check that we received the response we expect.
master
Damien Goutte-Gattat 2 months ago
parent
commit
a33a6f7f5b
  1. 8
      src/scheme-libcurl.c

8
src/scheme-libcurl.c

@ -33,13 +33,13 @@
#include <curl/curl.h>
static int
check_authentication(CURL *curl)
check_response(CURL *curl)
{
long http_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
return http_code == 401 ? 1 : 0;
return http_code == 200 || http_code == 201 ? 0 : 1;
}
@ -99,7 +99,7 @@ gfsec_scheme_libcurl_get_file(gfsec_scheme_t scheme,
if ( ret == 0 && curl_easy_perform(curl) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
if ( ret == 0 && check_authentication(curl) != 0 )
if ( ret == 0 && check_response(curl) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
if ( ret == 0 ) {
@ -182,7 +182,7 @@ gfsec_scheme_libcurl_put_file(gfsec_scheme_t scheme,
if ( ret == 0 && curl_easy_perform(curl) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
if ( ret == 0 && check_authentication(curl) != 0 )
if ( ret == 0 && check_response(curl) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
curl_easy_cleanup(curl);

Loading…
Cancel
Save