From e39dff5001bdd36bd2a2ca546ff19ea39965f79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sat, 19 Jun 2021 17:23:52 +0800 Subject: One handle for one request --- request.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'request.h') diff --git a/request.h b/request.h index 561891a..11444de 100644 --- a/request.h +++ b/request.h @@ -9,6 +9,7 @@ #include #include #ifndef __EMSCRIPTEN__ +#include #include #endif #include "icclient/typedefs.h" @@ -21,11 +22,9 @@ struct body { } pairs[16]; }; -#ifdef __EMSCRIPTEN__ -extern emscripten_fetch_attr_t attr; -#else -extern CURL *curl; +#ifndef __EMSCRIPTEN__ extern char *sampleurl; +extern char *certificate; size_t append(char *, size_t, size_t, icclient_response *); #endif @@ -89,6 +88,9 @@ static inline void request(void (*handler)(icclient_response *), void (*callback va_end(ap); #ifdef __EMSCRIPTEN__ + emscripten_fetch_attr_t attr; + emscripten_fetch_attr_init(&attr); + attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; if (handler) attr.onsuccess = handler; if (body) { @@ -117,6 +119,14 @@ static inline void request(void (*handler)(icclient_response *), void (*callback } emscripten_fetch(&attr, url); #else + CURL *curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); + if (certificate) + curl_easy_setopt(curl, CURLOPT_CAINFO, certificate); +#ifdef DEBUG + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); +#endif curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, append); icclient_response response = { .userData = callback, .numBytes = 0 }; @@ -151,6 +161,7 @@ static inline void request(void (*handler)(icclient_response *), void (*callback #endif } #endif + curl_easy_cleanup(curl); #endif } -- cgit v1.2.3