diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-07-30 15:57:10 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-07-30 16:06:57 +0200 |
commit | fd277f253027f03f3a7b0dc8acc935e799d645f5 (patch) | |
tree | 9fd95c6d18490158ff95819d128a713f74f19cd0 /src/curl | |
parent | ebc70e1bccd6c2f784df8630f1105a91bc7bfeed (diff) | |
download | gnunet-fd277f253027f03f3a7b0dc8acc935e799d645f5.tar.gz gnunet-fd277f253027f03f3a7b0dc8acc935e799d645f5.zip |
-fetch response code first before testing on it
Diffstat (limited to 'src/curl')
-rw-r--r-- | src/curl/curl.c | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c index 79aac74ce..71672c780 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c | |||
@@ -759,6 +759,15 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, | |||
759 | "Downloaded body: %.*s\n", | 759 | "Downloaded body: %.*s\n", |
760 | (int) db->buf_size, | 760 | (int) db->buf_size, |
761 | (char *) db->buf); | 761 | (char *) db->buf); |
762 | if (CURLE_OK != | ||
763 | curl_easy_getinfo (eh, | ||
764 | CURLINFO_RESPONSE_CODE, | ||
765 | response_code)) | ||
766 | { | ||
767 | /* unexpected error... */ | ||
768 | GNUNET_break (0); | ||
769 | *response_code = 0; | ||
770 | } | ||
762 | if ((CURLE_OK != | 771 | if ((CURLE_OK != |
763 | curl_easy_getinfo (eh, | 772 | curl_easy_getinfo (eh, |
764 | CURLINFO_CONTENT_TYPE, | 773 | CURLINFO_CONTENT_TYPE, |
@@ -768,15 +777,6 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, | |||
768 | { | 777 | { |
769 | /* No content type or explicitly not JSON, refuse to parse | 778 | /* No content type or explicitly not JSON, refuse to parse |
770 | (but keep response code) */ | 779 | (but keep response code) */ |
771 | if (CURLE_OK != | ||
772 | curl_easy_getinfo (eh, | ||
773 | CURLINFO_RESPONSE_CODE, | ||
774 | response_code)) | ||
775 | { | ||
776 | /* unexpected error... */ | ||
777 | GNUNET_break (0); | ||
778 | *response_code = 0; | ||
779 | } | ||
780 | if (0 != db->buf_size) | 780 | if (0 != db->buf_size) |
781 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 781 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
782 | "Did NOT detect response `%.*s' as JSON\n", | 782 | "Did NOT detect response `%.*s' as JSON\n", |
@@ -784,6 +784,8 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, | |||
784 | (const char *) db->buf); | 784 | (const char *) db->buf); |
785 | return NULL; | 785 | return NULL; |
786 | } | 786 | } |
787 | if (MHD_HTTP_NO_CONTENT == *response_code) | ||
788 | return NULL; | ||
787 | if (0 == *response_code) | 789 | if (0 == *response_code) |
788 | { | 790 | { |
789 | char *url; | 791 | char *url; |
@@ -798,8 +800,6 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, | |||
798 | url); | 800 | url); |
799 | return NULL; | 801 | return NULL; |
800 | } | 802 | } |
801 | if (MHD_HTTP_NO_CONTENT == *response_code) | ||
802 | return NULL; | ||
803 | json = NULL; | 803 | json = NULL; |
804 | if (0 == db->eno) | 804 | if (0 == db->eno) |
805 | { | 805 | { |
@@ -816,18 +816,6 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, | |||
816 | GNUNET_free (db->buf); | 816 | GNUNET_free (db->buf); |
817 | db->buf = NULL; | 817 | db->buf = NULL; |
818 | db->buf_size = 0; | 818 | db->buf_size = 0; |
819 | if (NULL != json) | ||
820 | { | ||
821 | if (CURLE_OK != | ||
822 | curl_easy_getinfo (eh, | ||
823 | CURLINFO_RESPONSE_CODE, | ||
824 | response_code)) | ||
825 | { | ||
826 | /* unexpected error... */ | ||
827 | GNUNET_break (0); | ||
828 | *response_code = 0; | ||
829 | } | ||
830 | } | ||
831 | return json; | 819 | return json; |
832 | } | 820 | } |
833 | 821 | ||