Skip to content

Commit

Permalink
request_user_agent option
Browse files Browse the repository at this point in the history
  • Loading branch information
cyga committed Nov 20, 2011
1 parent 6fba2db commit 607aa5d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions sql/www_fdw.sql
Expand Up @@ -12,6 +12,7 @@ CREATE TYPE WWWFdwOptions AS (
method_insert text, method_insert text,
method_delete text, method_delete text,
method_update text, method_update text,
request_user_agent text,
request_serialize_callback text, request_serialize_callback text,
request_serialize_type text, request_serialize_type text,
request_serialize_human_readable text, request_serialize_human_readable text,
Expand Down
12 changes: 12 additions & 0 deletions src/www_fdw.c
Expand Up @@ -57,6 +57,7 @@ static struct WWW_fdw_option valid_options[] =
{ "method_delete", ForeignServerRelationId }, { "method_delete", ForeignServerRelationId },
{ "method_update", ForeignServerRelationId }, { "method_update", ForeignServerRelationId },


{ "request_user_agent", ForeignServerRelationId },
{ "request_serialize_callback", ForeignServerRelationId }, { "request_serialize_callback", ForeignServerRelationId },
{ "request_serialize_type", ForeignServerRelationId }, { "request_serialize_type", ForeignServerRelationId },
{ "request_serialize_human_readable", ForeignServerRelationId }, { "request_serialize_human_readable", ForeignServerRelationId },
Expand All @@ -81,6 +82,7 @@ typedef struct WWW_fdw_options
char* method_insert; char* method_insert;
char* method_delete; char* method_delete;
char* method_update; char* method_update;
char* request_user_agent;
char* request_serialize_callback; char* request_serialize_callback;
char* request_serialize_type; char* request_serialize_type;
char* request_serialize_human_readable; char* request_serialize_human_readable;
Expand Down Expand Up @@ -182,6 +184,7 @@ www_fdw_validator(PG_FUNCTION_ARGS)
char *method_insert = NULL; char *method_insert = NULL;
char *method_delete = NULL; char *method_delete = NULL;
char *method_update = NULL; char *method_update = NULL;
char *request_user_agent= NULL;
char *request_serialize_callback = NULL; char *request_serialize_callback = NULL;
char *request_serialize_type = NULL; char *request_serialize_type = NULL;
char *request_serialize_human_readable = NULL; char *request_serialize_human_readable = NULL;
Expand Down Expand Up @@ -233,6 +236,7 @@ www_fdw_validator(PG_FUNCTION_ARGS)
if(parse_parameter("method_insert", &method_insert, def)) continue; if(parse_parameter("method_insert", &method_insert, def)) continue;
if(parse_parameter("method_delete", &method_delete, def)) continue; if(parse_parameter("method_delete", &method_delete, def)) continue;
if(parse_parameter("method_update", &method_update, 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_serialize_callback", &request_serialize_callback, 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_type", &request_serialize_type, def)) continue;
if(parse_parameter("request_serialize_human_readable", &request_serialize_human_readable, def)) if(parse_parameter("request_serialize_human_readable", &request_serialize_human_readable, def))
Expand Down Expand Up @@ -1152,6 +1156,7 @@ get_www_fdw_options(WWW_fdw_options *opts, Oid *opts_type, Datum *opts_value)
opts->method_delete, opts->method_delete,
opts->method_update, opts->method_update,


opts->request_user_agent,
opts->request_serialize_callback, opts->request_serialize_callback,
opts->request_serialize_type, opts->request_serialize_type,
opts->request_serialize_human_readable, opts->request_serialize_human_readable,
Expand Down Expand Up @@ -1518,6 +1523,7 @@ www_begin(ForeignScanState *node, int eflags)
/* interacting with the server */ /* interacting with the server */
curl = curl_easy_init(); curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url.data); curl_easy_setopt(curl, CURLOPT_URL, url.data);
curl_easy_setopt(curl, CURLOPT_USERAGENT, opts->request_user_agent);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer);
if(post.post || 0 == strcmp(opts->method_select, "POST")) if(post.post || 0 == strcmp(opts->method_select, "POST"))
{ {
Expand Down Expand Up @@ -1903,6 +1909,7 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
opts->method_insert = NULL; opts->method_insert = NULL;
opts->method_delete = NULL; opts->method_delete = NULL;
opts->method_update = NULL; opts->method_update = NULL;
opts->request_user_agent = NULL;
opts->request_serialize_callback = NULL; opts->request_serialize_callback = NULL;
opts->request_serialize_type = NULL; opts->request_serialize_type = NULL;
opts->request_serialize_human_readable = NULL; opts->request_serialize_human_readable = NULL;
Expand Down Expand Up @@ -1942,6 +1949,9 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
if (strcmp(def->defname, "method_update") == 0) if (strcmp(def->defname, "method_update") == 0)
opts->method_update = defGetString(def); opts->method_update = defGetString(def);


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

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


Expand Down Expand Up @@ -1972,6 +1982,8 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
if (!opts->method_delete) opts->method_delete = "DELETE"; if (!opts->method_delete) opts->method_delete = "DELETE";
if (!opts->method_update) opts->method_update = "POST"; if (!opts->method_update) opts->method_update = "POST";


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

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


Expand Down

0 comments on commit 607aa5d

Please sign in to comment.