aboutsummaryrefslogtreecommitdiff
path: root/src/curl/curl.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-21 20:43:18 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-21 20:43:18 +0200
commitbf99d2243fedaeb662b5d7b20138cf2ee064a110 (patch)
tree4681e2a2e4ea00a92fddad12bf31aeff54c4ae24 /src/curl/curl.c
parent13ceb583b892ecbe1094e473c058a6ff18ad0efb (diff)
downloadgnunet-bf99d2243fedaeb662b5d7b20138cf2ee064a110.tar.gz
gnunet-bf99d2243fedaeb662b5d7b20138cf2ee064a110.zip
fix #6191
Diffstat (limited to 'src/curl/curl.c')
-rw-r--r--src/curl/curl.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c
index da486ecc1..72bb17789 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -526,6 +526,40 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job)
526 526
527 527
528/** 528/**
529 * Test if the given content type @a ct is JSON
530 *
531 * @param ct a content type, i.e. "application/json; charset=UTF-8"
532 * @return true if @a ct denotes JSON
533 */
534static bool
535is_json (const char *ct)
536{
537 const char *semi;
538
539 /* check for "application/json" exact match */
540 if (0 == strcasecmp (ct,
541 "application/json"))
542 return true;
543 /* check for "application/json;[ANYTHING]" */
544 semi = strchr (ct,
545 ';');
546 /* also allow "application/json [ANYTHING]" (note the space!) */
547 if (NULL == semi)
548 semi = strchr (ct,
549 ' ');
550 if (NULL == semi)
551 return false; /* no delimiter we accept, forget it */
552 if (semi - ct != strlen ("application/json"))
553 return false; /* delimiter past desired length, forget it */
554 if (0 == strncasecmp (ct,
555 "application/json",
556 strlen ("application/json")))
557 return true; /* OK */
558 return false;
559}
560
561
562/**
529 * Obtain information about the final result about the 563 * Obtain information about the final result about the
530 * HTTP download. If the download was successful, parses 564 * HTTP download. If the download was successful, parses
531 * the JSON in the @a db and returns it. Also returns 565 * the JSON in the @a db and returns it. Also returns
@@ -562,8 +596,7 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
562 CURLINFO_CONTENT_TYPE, 596 CURLINFO_CONTENT_TYPE,
563 &ct)) || 597 &ct)) ||
564 (NULL == ct) || 598 (NULL == ct) ||
565 (0 != strcasecmp (ct, 599 (! is_json (ct)))
566 "application/json")))
567 { 600 {
568 /* No content type or explicitly not JSON, refuse to parse 601 /* No content type or explicitly not JSON, refuse to parse
569 (but keep response code) */ 602 (but keep response code) */