BEGIN; SET LOCAL client_min_messages = WARNING; CREATE EXTENSION IF NOT EXISTS pg_curl; END; DO $plpgsql$ BEGIN BEGIN PERFORM curl_easy_reset(); PERFORM curl_easy_setopt_timeout(1); PERFORM curl_easy_setopt_url('http://localhost/status/202'); PERFORM curl_easy_perform(); PERFORM curl_easy_getinfo_http_connectcode(); SET pg_curl.httpbin = 'http://localhost'; EXCEPTION WHEN OTHERS THEN SET pg_curl.httpbin = 'https://httpbin.org'; END; END;$plpgsql$; BEGIN; select curl_easy_reset(); curl_easy_reset ----------------- t (1 row) select curl_easy_setopt_url(current_setting('pg_curl.httpbin') || '/headers'); curl_easy_setopt_url ---------------------- t (1 row) select curl_header_append('X-Pg-Curl-Test', 'one'); curl_header_append -------------------- t (1 row) select curl_easy_perform(); curl_easy_perform ------------------- t (1 row) select (convert_from(curl_easy_getinfo_data_in(), 'utf-8')::jsonb -> 'headers' ->> 'X-Pg-Curl-Test') = 'one' as first_sent; first_sent ------------ t (1 row) -- curl_easy_header_reset() frees the header list; the easy handle must be -- detached from it too, or the next perform on the same handle walks freed -- memory (garbage headers or a backend crash) instead of sending none select curl_easy_header_reset(); curl_easy_header_reset ------------------------ t (1 row) select curl_easy_perform(); curl_easy_perform ------------------- t (1 row) select (convert_from(curl_easy_getinfo_data_in(), 'utf-8')::jsonb -> 'headers' ->> 'X-Pg-Curl-Test') is null as reset_not_sent; reset_not_sent ---------------- t (1 row) -- a header appended after the reset is sent as usual select curl_header_append('X-Pg-Curl-Test', 'two'); curl_header_append -------------------- t (1 row) select curl_easy_perform(); curl_easy_perform ------------------- t (1 row) select (convert_from(curl_easy_getinfo_data_in(), 'utf-8')::jsonb -> 'headers' ->> 'X-Pg-Curl-Test') = 'two' as new_sent; new_sent ---------- t (1 row) END;