Giter Club home page Giter Club logo

Comments (4)

cyga avatar cyga commented on June 27, 2024

no, it wasn't implemented.

if you want static configurable header, you can add it in the code:

  1. parse options, grep for "method_update", it has to be similar.
  2. setting headers section:
            /* in the src/www_fdw.c */
            curl_opts = curl_slist_append(curl_opts, "Content-type:");
            curl_opts = curl_slist_append(curl_opts, post.content_type.data);

from www_fdw.

KrzysztofCzajkaTURCOM avatar KrzysztofCzajkaTURCOM commented on June 27, 2024

Introducing new parameter: request_user_header.
Now you can push own HTTP header.
Clickmeeting need to set X-Api-Key in header.


@@ -64,10 +64,11 @@ static struct WWW_fdw_option valid_options[] =
    { "method_insert",  ForeignServerRelationId },
    { "method_delete",  ForeignServerRelationId },
    { "method_update",  ForeignServerRelationId },

    { "request_user_agent", ForeignServerRelationId },
+        { "request_user_header",ForeignServerRelationId },
    { "request_serialize_callback", ForeignServerRelationId },
    { "request_serialize_type", ForeignServerRelationId },
    { "request_serialize_human_readable",   ForeignServerRelationId },

    { "response_type",  ForeignServerRelationId },
@@ -95,10 +96,11 @@ typedef struct  WWW_fdw_options
    char*   method_select;
    char*   method_insert;
    char*   method_delete;
    char*   method_update;
    char*   request_user_agent;
+        char*   request_user_header;
    char*   request_serialize_callback;
    char*   request_serialize_type;
    char*   request_serialize_human_readable;
    char*   response_type;
    char*   response_deserialize_callback;
@@ -220,10 +222,11 @@ www_fdw_validator(PG_FUNCTION_ARGS)
    char        *method_select  = NULL;
    char        *method_insert  = NULL;
    char        *method_delete  = NULL;
    char        *method_update  = NULL;
    char        *request_user_agent= NULL;
+        char            *request_user_header = NULL;
    char        *request_serialize_callback = NULL;
    char        *request_serialize_type = NULL;
    char        *request_serialize_human_readable   = NULL;
    char        *response_type  = NULL;
    char        *response_deserialize_callback  = NULL;
@@ -277,10 +280,11 @@ www_fdw_validator(PG_FUNCTION_ARGS)
        if(parse_parameter("method_select", &method_select, def)) continue;
        if(parse_parameter("method_insert", &method_insert, def)) continue;
        if(parse_parameter("method_delete", &method_delete, def)) continue;
        if(parse_parameter("method_update", &method_update, def)) continue;
        if(parse_parameter("request_user_agent", &request_user_agent, def)) continue;
+                if(parse_parameter("request_user_header", &request_user_header, def)) continue;
        if(parse_parameter("request_serialize_callback", &request_serialize_callback, def)) continue;
        if(parse_parameter("request_serialize_type", &request_serialize_type, def)) continue;
        if(parse_parameter("request_serialize_human_readable", &request_serialize_human_readable, def))
        {
            if(
@@ -1396,10 +1400,11 @@ get_www_fdw_options(WWW_fdw_options *opts, Oid *opts_type, Datum *opts_value)
        opts->method_insert,
        opts->method_delete,
        opts->method_update,

        opts->request_user_agent,
+                opts->request_user_header,
        opts->request_serialize_callback,
        opts->request_serialize_type,
        opts->request_serialize_human_readable,

        opts->response_type,
@@ -1729,10 +1734,11 @@ www_begin(ForeignScanState *node, int eflags)
    StringInfoData  buffer;
    Oid             opts_type   = 0;
    Datum           opts_value  = 0;
    PostParameters  post;
    struct curl_slist   *curl_opts = NULL;
+        int                     header_set = 0;

    d("www_begin routine");

    /*
     * Do nothing in EXPLAIN
@@ -1777,23 +1783,33 @@ www_begin(ForeignScanState *node, int eflags)

    /* interacting with the server */
    curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, url.data);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, opts->request_user_agent);
+        if(opts->request_user_header)
+        {
+            curl_opts = curl_slist_append(curl_opts, opts->request_user_header);
+        }
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer);
    if(post.post || 0 == strcmp(opts->method_select, "POST"))
    {
        curl_easy_setopt(curl, CURLOPT_POST, 1);
        if(0 < post.content_type.len)
        {
            curl_opts = curl_slist_append(curl_opts, "Content-type:");
            curl_opts = curl_slist_append(curl_opts, post.content_type.data);
            curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_opts);
+                        header_set = 1;
        }
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.data.data);
    }

+        if ((opts->request_user_header)&&(0 == header_set))
+        {
+            curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_opts);
+        }
+
    /* prepare parsers */
    if( 0 == strcmp(opts->response_type, "json") )
    {
        if(opts->response_deserialize_callback)
        {
@@ -2234,10 +2250,13 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
            opts->method_update = defGetString(def);

        if (strcmp(def->defname, "request_user_agent") == 0)
            opts->request_user_agent    = defGetString(def);

+       if (strcmp(def->defname, "request_user_header") == 0)
+           opts->request_user_header   = defGetString(def);
+
        if (strcmp(def->defname, "request_serialize_callback") == 0)
            opts->request_serialize_callback    = defGetString(def);

        if (strcmp(def->defname, "request_serialize_type") == 0)
            opts->request_serialize_type    = defGetString(def);
@@ -2280,10 +2299,11 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
    if (!opts->method_insert) opts->method_insert   = "PUT";
    if (!opts->method_delete) opts->method_delete   = "DELETE";
    if (!opts->method_update) opts->method_update   = "POST";

    if (!opts->request_user_agent) opts->request_user_agent = "www_fdw postgres extension";
+        if (!opts->request_user_header) opts->request_user_header = "";

    if (!opts->request_serialize_type) opts->request_serialize_type = "log";
    if (!opts->request_serialize_human_readable) opts->request_serialize_human_readable = "0";

    if (!opts->response_type) opts->response_type   = "json";


from www_fdw.

jmealo avatar jmealo commented on June 27, 2024

@KrzysztofCzajkaTURCOM Any chance you can create a pull request with your changes?

from www_fdw.

cyga avatar cyga commented on June 27, 2024

@jmealo it's already in the HEAD

from www_fdw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.