Skip to content
This repository
Browse code

request_user_agent option

  • Loading branch information...
commit 607aa5d1f1f1c649cf906c91840d990468585e64 1 parent 6fba2db
Alex Sudakov authored November 20, 2011
1  sql/www_fdw.sql
@@ -12,6 +12,7 @@ CREATE TYPE WWWFdwOptions AS (
12 12
 	method_insert						text,
13 13
 	method_delete						text,
14 14
 	method_update						text,
  15
+	request_user_agent					text,
15 16
 	request_serialize_callback			text,
16 17
 	request_serialize_type				text,
17 18
 	request_serialize_human_readable	text,
12  src/www_fdw.c
@@ -57,6 +57,7 @@ static struct WWW_fdw_option valid_options[] =
57 57
 	{ "method_delete",	ForeignServerRelationId },
58 58
 	{ "method_update",	ForeignServerRelationId },
59 59
 
  60
+	{ "request_user_agent",	ForeignServerRelationId },
60 61
 	{ "request_serialize_callback",	ForeignServerRelationId },
61 62
 	{ "request_serialize_type",	ForeignServerRelationId },
62 63
 	{ "request_serialize_human_readable",	ForeignServerRelationId },
@@ -81,6 +82,7 @@ typedef struct	WWW_fdw_options
81 82
 	char*	method_insert;
82 83
 	char*	method_delete;
83 84
 	char*	method_update;
  85
+	char*	request_user_agent;
84 86
 	char*	request_serialize_callback;
85 87
 	char*	request_serialize_type;
86 88
 	char*	request_serialize_human_readable;
@@ -182,6 +184,7 @@ www_fdw_validator(PG_FUNCTION_ARGS)
182 184
 	char		*method_insert	= NULL;
183 185
 	char		*method_delete	= NULL;
184 186
 	char		*method_update	= NULL;
  187
+	char		*request_user_agent= NULL;
185 188
 	char		*request_serialize_callback	= NULL;
186 189
 	char		*request_serialize_type	= NULL;
187 190
 	char		*request_serialize_human_readable	= NULL;
@@ -233,6 +236,7 @@ www_fdw_validator(PG_FUNCTION_ARGS)
233 236
 		if(parse_parameter("method_insert", &method_insert, def)) continue;
234 237
 		if(parse_parameter("method_delete", &method_delete, def)) continue;
235 238
 		if(parse_parameter("method_update", &method_update, def)) continue;
  239
+		if(parse_parameter("request_user_agent", &request_user_agent, def)) continue;
236 240
 		if(parse_parameter("request_serialize_callback", &request_serialize_callback, def)) continue;
237 241
 		if(parse_parameter("request_serialize_type", &request_serialize_type, def)) continue;
238 242
 		if(parse_parameter("request_serialize_human_readable", &request_serialize_human_readable, def))
@@ -1152,6 +1156,7 @@ get_www_fdw_options(WWW_fdw_options *opts, Oid *opts_type, Datum *opts_value)
1152 1156
 		opts->method_delete,
1153 1157
 		opts->method_update,
1154 1158
 
  1159
+		opts->request_user_agent,
1155 1160
 		opts->request_serialize_callback,
1156 1161
 		opts->request_serialize_type,
1157 1162
 		opts->request_serialize_human_readable,
@@ -1518,6 +1523,7 @@ www_begin(ForeignScanState *node, int eflags)
1518 1523
 	/* interacting with the server */
1519 1524
 	curl = curl_easy_init();
1520 1525
 	curl_easy_setopt(curl, CURLOPT_URL, url.data);
  1526
+	curl_easy_setopt(curl, CURLOPT_USERAGENT, opts->request_user_agent);
1521 1527
 	curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer);
1522 1528
 	if(post.post || 0 == strcmp(opts->method_select, "POST"))
1523 1529
 	{
@@ -1903,6 +1909,7 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
1903 1909
 	opts->method_insert	= NULL;
1904 1910
 	opts->method_delete	= NULL;
1905 1911
 	opts->method_update	= NULL;
  1912
+	opts->request_user_agent	= NULL;
1906 1913
 	opts->request_serialize_callback	= NULL;
1907 1914
 	opts->request_serialize_type	= NULL;
1908 1915
 	opts->request_serialize_human_readable	= NULL;
@@ -1942,6 +1949,9 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
1942 1949
 		if (strcmp(def->defname, "method_update") == 0)
1943 1950
 			opts->method_update	= defGetString(def);
1944 1951
 
  1952
+		if (strcmp(def->defname, "request_user_agent") == 0)
  1953
+			opts->request_user_agent	= defGetString(def);
  1954
+
1945 1955
 		if (strcmp(def->defname, "request_serialize_callback") == 0)
1946 1956
 			opts->request_serialize_callback	= defGetString(def);
1947 1957
 
@@ -1972,6 +1982,8 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
1972 1982
 	if (!opts->method_delete) opts->method_delete	= "DELETE";
1973 1983
 	if (!opts->method_update) opts->method_update	= "POST";
1974 1984
 
  1985
+	if (!opts->request_user_agent) opts->request_user_agent	= "www_fdw postgres extension";
  1986
+
1975 1987
 	if (!opts->request_serialize_type) opts->request_serialize_type	= "log";
1976 1988
 	if (!opts->request_serialize_human_readable) opts->request_serialize_human_readable	= "0";
1977 1989
 

0 notes on commit 607aa5d

Please sign in to comment.
Something went wrong with that request. Please try again.