frosix_api_curl_defaults.c (2078B)
1 /* 2 This file is part of Frosix 3 Copyright (C) 2014-2019 Anastasis SARL 4 5 Frosix is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 Frosix is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 Frosix; see the file COPYING. If not, see 15 <http://www.gnu.org/licenses/> 16 */ 17 /** 18 * @file restclient/frosix_api_curl_defaults.c 19 * @brief curl easy handle defaults 20 * @author Florian Dold 21 */ 22 #include "platform.h" 23 #include "frosix_api_curl_defaults.h" 24 25 CURL * 26 FROSIX_curl_easy_get_ (const char *url) 27 { 28 CURL *eh; 29 30 eh = curl_easy_init (); 31 if (NULL == eh) 32 return NULL; 33 GNUNET_assert (CURLE_OK == 34 curl_easy_setopt (eh, 35 CURLOPT_URL, 36 url)); 37 GNUNET_assert (CURLE_OK == 38 curl_easy_setopt (eh, 39 CURLOPT_FOLLOWLOCATION, 40 1L)); 41 GNUNET_assert (CURLE_OK == 42 curl_easy_setopt (eh, 43 CURLOPT_TCP_FASTOPEN, 44 1L)); 45 /* limit MAXREDIRS to 5 as a simple security measure against 46 a potential infinite loop caused by a malicious target */ 47 GNUNET_assert (CURLE_OK == 48 curl_easy_setopt (eh, 49 CURLOPT_MAXREDIRS, 50 5L)); 51 /* Enable compression (using whatever curl likes), see 52 https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html */ 53 GNUNET_break (CURLE_OK == 54 curl_easy_setopt (eh, 55 CURLOPT_ACCEPT_ENCODING, 56 "")); 57 return eh; 58 }