Skip to content

Commit 38fcf8f

Browse files
committed
Reset all non-user options before returning handle for
use.
1 parent f8df55b commit 38fcf8f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

http.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ header_array_to_slist(ArrayType *array, struct curl_slist *headers)
472472
iterator = array_create_iterator(array, 0);
473473
#endif
474474

475-
while( array_iterate(iterator, &value, &isnull) )
475+
while (array_iterate(iterator, &value, &isnull))
476476
{
477477
HeapTupleHeader rec;
478478
HeapTupleData tuple;
@@ -720,12 +720,18 @@ http_get_handle()
720720
/* User can over-ride with http_set_curlopt() if they wish */
721721
curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 1);
722722
}
723+
/* Always reset because we're going to infull the user */
724+
/* set options down below */
725+
else
726+
{
727+
curl_easy_reset(handle);
728+
}
723729

724730
if (!handle)
725731
ereport(ERROR, (errmsg("Unable to initialize CURL")));
726732

727-
/* Persist any options that have been set on the handle this session */
728-
while(1)
733+
/* Bring in any options the users has set this session */
734+
while (1)
729735
{
730736
opt = settable_curlopts[i++];
731737
if (!opt.curlopt_str) break;
@@ -748,10 +754,10 @@ Datum http_reset_curlopt(PG_FUNCTION_ARGS)
748754
{
749755
int i = 0;
750756
/* Set up global HTTP handle */
751-
g_http_handle = http_get_handle();
752-
curl_easy_reset(g_http_handle);
757+
CURL * handle = http_get_handle();
758+
curl_easy_reset(handle);
753759

754-
while(1)
760+
while (1)
755761
{
756762
http_curlopt *opt = settable_curlopts + i++;
757763
if (!opt->curlopt_str) break;
@@ -789,7 +795,7 @@ Datum http_set_curlopt(PG_FUNCTION_ARGS)
789795
curlopt = text_to_cstring(curlopt_txt);
790796
value = text_to_cstring(value_txt);
791797

792-
while(1)
798+
while (1)
793799
{
794800
http_curlopt *opt = settable_curlopts + i++;
795801
if (!opt->curlopt_str) break;

0 commit comments

Comments
 (0)