Blob Blame History Raw
From: Jarrod Baumann <jarrod@unixc.org>
Date: Fri, 24 Apr 2015 19:10:46 +0300
Subject: [PATCH] Populate the rcode pval in rest get/post methods before
 returning error

(cherry picked from commit fa37b3dd8df4a02d42503cf5ab8c8de8be528c33)

diff --git a/modules/rest_client/rest_methods.c b/modules/rest_client/rest_methods.c
index 9ae53d5..24bc7bf 100644
--- a/modules/rest_client/rest_methods.c
+++ b/modules/rest_client/rest_methods.c
@@ -75,6 +75,20 @@ int rest_get_method(struct sip_msg *msg, char *url,
 	curl_easy_setopt(handle, CURLOPT_WRITEHEADER, &st);
 
 	rc = curl_easy_perform(handle);
+
+	if (code_pv) {
+		curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_rc);
+		LM_DBG("Last response code: %ld\n", http_rc);
+
+		pv_val.flags = PV_VAL_INT|PV_TYPE_INT;
+		pv_val.ri = (int)http_rc;
+
+		if (pv_set_value(msg, code_pv, 0, &pv_val) != 0) {
+			LM_ERR("Set code pv value failed!\n");
+			goto error;
+		}
+	}
+
 	if (rc != CURLE_OK) {
 		LM_ERR("Error [%i] while performing curl operation\n", rc);
 		LM_ERR("[%s]\n", err_buff);
@@ -105,19 +119,6 @@ int rest_get_method(struct sip_msg *msg, char *url,
 		}
 	}
 
-	if (code_pv) {
-		curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_rc);
-		LM_DBG("Last response code: %ld\n", http_rc);
-
-		pv_val.flags = PV_VAL_INT|PV_TYPE_INT;
-		pv_val.ri = (int)http_rc;
-
-		if (pv_set_value(msg, code_pv, 0, &pv_val) != 0) {
-			LM_ERR("Set code pv value failed!\n");
-			goto error;
-		}
-	}
-
 	curl_easy_cleanup(handle);
 	return 1;
 
@@ -179,6 +180,19 @@ int rest_post_method(struct sip_msg *msg, char *url, char *ctype, char *body,
 	curl_easy_setopt(handle, CURLOPT_WRITEHEADER, &st);
 
 	rc = curl_easy_perform(handle);
+	if (code_pv) {
+		curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_rc);
+		LM_DBG("Last response code: %ld\n", http_rc);
+
+		pv_val.flags = PV_VAL_INT|PV_TYPE_INT;
+		pv_val.ri = (int)http_rc;
+
+		if (pv_set_value(msg, code_pv, 0, &pv_val) != 0) {
+			LM_ERR("Set code pv value failed!\n");
+			goto error;
+		}
+	}
+
 	curl_slist_free_all(list);
 
 	if (rc != CURLE_OK) {
@@ -211,19 +225,6 @@ int rest_post_method(struct sip_msg *msg, char *url, char *ctype, char *body,
 		}
 	}
 
-	if (code_pv) {
-		curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_rc);
-		LM_DBG("Last response code: %ld\n", http_rc);
-
-		pv_val.flags = PV_VAL_INT|PV_TYPE_INT;
-		pv_val.ri = (int)http_rc;
-
-		if (pv_set_value(msg, code_pv, 0, &pv_val) != 0) {
-			LM_ERR("Set code pv value failed!\n");
-			goto error;
-		}
-	}
-
 	curl_easy_cleanup(handle);
 	return 1;