@@ -70,6 +70,7 @@ static void CurlGlobalCleanup(int code, Datum arg);
7070static void CurlCleanup (CURL * curl , struct curl_slist * headerList );
7171static HttpResult CurlReturnError (CURL * curl , struct curl_slist * headerList ,
7272 CURLcode curlCode , const char * errorMsg );
73+ static const char * HttpRequestMethodToString (HttpMethod method );
7374
7475#define CURL_SETOPT (curl , opt , value ) do { \
7576 curlCode = curl_easy_setopt((curl), (opt), (value)); \
@@ -82,6 +83,9 @@ static HttpResult CurlReturnError(CURL * curl, struct curl_slist *headerList,
8283static bool curlInitialized = false;
8384
8485
86+ bool HttpClientTraceTraffic = false;
87+
88+
8589/*
8690 * CurlGloballyInitIfNotInitialized globally initiates curl state if not initialized.
8791 */
@@ -447,6 +451,21 @@ HttpCommonNoThrows(HttpMethod method, const char *url, const char *postData, con
447451 struct curl_slist * curlHeaders = NULL ;
448452 CURLcode curlCode = CURLE_OK ;
449453
454+ if (HttpClientTraceTraffic && message_level_is_interesting (INFO ))
455+ {
456+ StringInfo postDataInfo = NULL ;
457+
458+ if (postData )
459+ {
460+ postDataInfo = makeStringInfo ();
461+ appendStringInfo (postDataInfo , " : {%s}" , postData );
462+ }
463+
464+ ereport (INFO , (errmsg ("making %s request to URL %s%s" ,
465+ HttpRequestMethodToString (method ), url ,
466+ postDataInfo ? postDataInfo -> data : "" )));
467+ }
468+
450469 if (!CheckMinCurlVersion (curl_version_info (CURLVERSION_NOW )))
451470 return CurlReturnError (curl , curlHeaders , CURLE_FAILED_INIT , "pg_lake_iceberg requires Curl version 7.20.0 or higher" );
452471
@@ -508,5 +527,32 @@ HttpCommonNoThrows(HttpMethod method, const char *url, const char *postData, con
508527
509528 ereport (DEBUG4 , (errmsg ("libcurl request completed successfully" )));
510529
530+ if (HttpClientTraceTraffic && message_level_is_interesting (INFO ))
531+ {
532+ ereport (INFO , (errmsg ("received response with status code %ld, body: %s" ,
533+ res .status , res .body ? res .body : "<empty>" )));
534+ }
535+
511536 return res ;
512537}
538+
539+
540+ static const char *
541+ HttpRequestMethodToString (HttpMethod method )
542+ {
543+ switch (method )
544+ {
545+ case HTTP_GET :
546+ return "GET" ;
547+ case HTTP_HEAD :
548+ return "HEAD" ;
549+ case HTTP_POST :
550+ return "POST" ;
551+ case HTTP_PUT :
552+ return "PUT" ;
553+ case HTTP_DELETE :
554+ return "DELETE" ;
555+ default :
556+ return "UNKNOWN" ;
557+ }
558+ }
0 commit comments