diff options
author | Julien Dessaux | 2019-08-04 11:33:58 +0200 |
---|---|---|
committer | Julien Dessaux | 2019-08-05 13:28:55 +0200 |
commit | 2d542a79796fb4568871c4a634ce4d3b311ffd9d (patch) | |
tree | d62ebaf77d35308df420e930de07389810b2abc4 | |
parent | Added http lib and basic restapi with rocket_close_im binary (diff) | |
download | rocket-cli-client-2d542a79796fb4568871c4a634ce4d3b311ffd9d.tar.gz rocket-cli-client-2d542a79796fb4568871c4a634ce4d3b311ffd9d.tar.bz2 rocket-cli-client-2d542a79796fb4568871c4a634ce4d3b311ffd9d.zip |
Fixed curl call orders
Diffstat (limited to '')
-rw-r--r-- | common/http.c | 9 | ||||
-rw-r--r-- | restapi/auth.c | 1 | ||||
-rw-r--r-- | restapi/im.c | 1 |
3 files changed, 7 insertions, 4 deletions
diff --git a/common/http.c b/common/http.c index 275a18f..88e15cd 100644 --- a/common/http.c +++ b/common/http.c @@ -53,6 +53,9 @@ void http_clean(void) const char * http_get(const char* path) { + curl_easy_reset(curl); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback); + curl_easy_setopt(curl, CURLOPT_POST, 0); return http_perform(path, NULL); } @@ -80,9 +83,6 @@ const char * http_perform(const char* path, const char* postfields) buffer_fill = 0; } - curl_easy_reset(curl); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback); - const char * weburl = config_get_web_url(); size_t weburl_len = strlen(weburl); size_t path_len = strlen(path); @@ -106,6 +106,9 @@ const char * http_perform(const char* path, const char* postfields) const char * http_post(const char* path, const char* postfields) { + curl_easy_reset(curl); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback); + if (postfields == NULL) curl_easy_setopt(curl, CURLOPT_POST, 1); return http_perform(path, postfields); diff --git a/restapi/auth.c b/restapi/auth.c index e3f1b74..ad13798 100644 --- a/restapi/auth.c +++ b/restapi/auth.c @@ -60,6 +60,7 @@ restapi_login(const char* username, const char* password) printf("userid: %s\nauthtoken: %s\n", userId->valuestring, authToken->valuestring); http_add_header("X-User-Id", userId->valuestring); http_add_header("X-Auth-Token", authToken->valuestring); + http_add_header("Content-type", "application/json"); } else { const cJSON* msg = cJSON_GetObjectItemCaseSensitive(json, "message"); if (cJSON_IsString(msg) && msg->valuestring != NULL) diff --git a/restapi/im.c b/restapi/im.c index 6b9f75c..0c49cb0 100644 --- a/restapi/im.c +++ b/restapi/im.c @@ -22,7 +22,6 @@ restapi_im_close(const char* username) strcpy(login_args, LOGIN_ARG_PRE); strcpy(login_args + pre_len, username); strcpy(login_args + pre_len + user_len, LOGIN_ARG_POST); - http_add_header("Content-type", "application/json"); const char* buffer = http_post("/api/v1/im.close", login_args); free(login_args); |