diff --git a/META.json b/META.json index 990d9a6..a49d8e8 100644 --- a/META.json +++ b/META.json @@ -2,7 +2,7 @@ "name": "http", "abstract": "HTTP client for PostgreSQL", "description": "HTTP allows you to get the content of a web page in a SQL function call.", - "version": "1.2", + "version": "1.3", "maintainer": [ "Paul Ramsey " ], @@ -21,9 +21,9 @@ }, "provides": { "http": { - "file": "http--1.2.sql", + "file": "http--1.3.sql", "docfile": "README.md", - "version": "1.2", + "version": "1.3", "abstract": "HTTP client for PostgreSQL" }, }, diff --git a/Makefile b/Makefile index bccf427..977f76b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ MODULE_big = http OBJS = http.o EXTENSION = http -DATA = http--1.2.sql http--1.1--1.2.sql http--1.0--1.1.sql +DATA = http--1.3.sql http--1.2--1.3.sql http--1.1--1.2.sql http--1.0--1.1.sql REGRESS = http EXTRA_CLEAN = diff --git a/README.md b/README.md index 9940ecd..c5a0e0f 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,14 @@ This extension is for that. 200 | application/json | some text + > SELECT status, content_type, content::json->>'data' AS data + FROM http_patch('http://httpbin.org/patch', '{"this":"that"}', 'application/json'); + + status | content_type | data + --------+------------------+----------- + 200 | application/json | some text + + > SELECT status, content_type, content::json->>'url' AS url FROM http_delete('http://httpbin.org/delete'); diff --git a/http--1.2--1.3.sql b/http--1.2--1.3.sql new file mode 100644 index 0000000..59ccf0c --- /dev/null +++ b/http--1.2--1.3.sql @@ -0,0 +1,14 @@ +ALTER DOMAIN http_method DROP CONSTRAINT http_method_check; +ALTER DOMAIN http_method ADD CHECK ( + VALUE ILIKE 'get' OR + VALUE ILIKE 'post' OR + VALUE ILIKE 'put' OR + VALUE ILIKE 'delete' OR + VALUE ILIKE 'patch' OR + VALUE ILIKE 'head' +); + +CREATE OR REPLACE FUNCTION http_patch(uri VARCHAR, content VARCHAR, content_type VARCHAR) + RETURNS http_response + AS $$ SELECT http(('PATCH', $1, NULL, $3, $2)::http_request) $$ + LANGUAGE 'sql'; diff --git a/http--1.2.sql b/http--1.3.sql similarity index 100% rename from http--1.2.sql rename to http--1.3.sql diff --git a/http.c b/http.c index 60c897a..5e90419 100644 --- a/http.c +++ b/http.c @@ -28,7 +28,7 @@ ***********************************************************************/ /* Constants */ -#define HTTP_VERSION "1.2.4" +#define HTTP_VERSION "1.3.0" #define HTTP_ENCODING "gzip" #define CURL_MIN_VERSION 0x071400 /* 7.20.0 */ @@ -80,7 +80,8 @@ typedef enum { HTTP_POST, HTTP_DELETE, HTTP_PUT, - HTTP_HEAD + HTTP_HEAD, + HTTP_PATCH } http_method; /* Components (and postitions) of the http_request tuple type */ @@ -392,6 +393,8 @@ request_type(const char *method) return HTTP_DELETE; else if ( strcasecmp(method, "HEAD") == 0 ) return HTTP_HEAD; + else if ( strcasecmp(method, "PATCH") == 0 ) + return HTTP_PATCH; else return HTTP_GET; } @@ -1045,8 +1048,10 @@ Datum http_request(PG_FUNCTION_ARGS) } CURL_SETOPT(g_http_handle, CURLOPT_POSTFIELDS, text_to_cstring(content_text)); } - else if ( method == HTTP_PUT ) + else if ( method == HTTP_PUT || method == HTTP_PATCH ) { + if ( method == HTTP_PATCH ) + CURL_SETOPT(g_http_handle, CURLOPT_CUSTOMREQUEST, "PATCH"); initStringInfo(&si_read); appendBinaryStringInfo(&si_read, VARDATA(content_text), content_size); CURL_SETOPT(g_http_handle, CURLOPT_UPLOAD, 1); diff --git a/http.control b/http.control index 5270225..a452b0b 100644 --- a/http.control +++ b/http.control @@ -1,4 +1,4 @@ -default_version = '1.2' +default_version = '1.3' module_pathname = '$libdir/http' relocatable = true comment = 'HTTP client for PostgreSQL, allows web page retrieval inside the database.'