Skip to content

Commit

Permalink
Add PATCH method
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Sep 27, 2018
1 parent 9c444c9 commit 6010455
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
6 changes: 3 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"
],
Expand All @@ -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"
},
},
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
14 changes: 14 additions & 0 deletions http--1.2--1.3.sql
Original file line number Diff line number Diff line change
@@ -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';
File renamed without changes.
11 changes: 8 additions & 3 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion http.control
Original file line number Diff line number Diff line change
@@ -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.'

0 comments on commit 6010455

Please sign in to comment.