Skip to content

Commit

Permalink
Support PgSQL 12, and use https in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Mar 25, 2019
1 parent 4a2321b commit 9fd8e9c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 62 deletions.
92 changes: 46 additions & 46 deletions expected/http.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SELECT http_set_curlopt('CURLOPT_TIMEOUT', '10');

-- Status code
SELECT status
FROM http_get('http://httpbin.org/status/202');
FROM http_get('https://httpbin.org/status/202');
status
--------
202
Expand All @@ -18,7 +18,7 @@ FROM http_get('http://httpbin.org/status/202');
SELECT *
FROM (
SELECT (unnest(headers)).*
FROM http_get('http://httpbin.org/response-headers?Abcde=abcde')
FROM http_get('https://httpbin.org/response-headers?Abcde=abcde')
) a
WHERE field = 'Abcde';
field | value
Expand All @@ -31,12 +31,12 @@ SELECT status,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_get('http://httpbin.org/anything?foo=bar');
status | args | url | method
--------+------------------+---------------------------------------+--------
200 | { +| "http://httpbin.org/anything?foo=bar" | "GET"
| "foo": "bar"+| |
| } | |
FROM http_get('https://httpbin.org/anything?foo=bar');
status | args | url | method
--------+------------------+----------------------------------------+--------
200 | { +| "https://httpbin.org/anything?foo=bar" | "GET"
| "foo": "bar"+| |
| } | |
(1 row)

-- GET with data
Expand All @@ -45,23 +45,23 @@ content::json->'args' as args,
content::json->>'data' as data,
content::json->'url' as url,
content::json->'method' as method
from http(('GET', 'http://httpbin.org/anything', NULL, 'application/json', '{"search": "toto"}'));
status | args | data | url | method
--------+------+--------------------+-------------------------------+--------
200 | {} | {"search": "toto"} | "http://httpbin.org/anything" | "GET"
from http(('GET', 'https://httpbin.org/anything', NULL, 'application/json', '{"search": "toto"}'));
status | args | data | url | method
--------+------+--------------------+--------------------------------+--------
200 | {} | {"search": "toto"} | "https://httpbin.org/anything" | "GET"
(1 row)

-- DELETE
SELECT status,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_delete('http://httpbin.org/anything?foo=bar');
status | args | url | method
--------+------------------+---------------------------------------+----------
200 | { +| "http://httpbin.org/anything?foo=bar" | "DELETE"
| "foo": "bar"+| |
| } | |
FROM http_delete('https://httpbin.org/anything?foo=bar');
status | args | url | method
--------+------------------+----------------------------------------+----------
200 | { +| "https://httpbin.org/anything?foo=bar" | "DELETE"
| "foo": "bar"+| |
| } | |
(1 row)

-- PUT
Expand All @@ -70,12 +70,12 @@ content::json->'data' AS data,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_put('http://httpbin.org/anything?foo=bar','payload','text/plain');
status | data | args | url | method
--------+-----------+------------------+---------------------------------------+--------
200 | "payload" | { +| "http://httpbin.org/anything?foo=bar" | "PUT"
| | "foo": "bar"+| |
| | } | |
FROM http_put('https://httpbin.org/anything?foo=bar','payload','text/plain');
status | data | args | url | method
--------+-----------+------------------+----------------------------------------+--------
200 | "payload" | { +| "https://httpbin.org/anything?foo=bar" | "PUT"
| | "foo": "bar"+| |
| | } | |
(1 row)

-- PATCH
Expand All @@ -84,12 +84,12 @@ content::json->'data' AS data,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_patch('http://httpbin.org/anything?foo=bar','{"this":"that"}','application/json');
status | data | args | url | method
--------+-----------------------+------------------+---------------------------------------+---------
200 | "{\"this\":\"that\"}" | { +| "http://httpbin.org/anything?foo=bar" | "PATCH"
| | "foo": "bar"+| |
| | } | |
FROM http_patch('https://httpbin.org/anything?foo=bar','{"this":"that"}','application/json');
status | data | args | url | method
--------+-----------------------+------------------+----------------------------------------+---------
200 | "{\"this\":\"that\"}" | { +| "https://httpbin.org/anything?foo=bar" | "PATCH"
| | "foo": "bar"+| |
| | } | |
(1 row)

-- POST
Expand All @@ -98,19 +98,19 @@ content::json->'data' AS data,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_post('http://httpbin.org/anything?foo=bar','payload','text/plain');
status | data | args | url | method
--------+-----------+------------------+---------------------------------------+--------
200 | "payload" | { +| "http://httpbin.org/anything?foo=bar" | "POST"
| | "foo": "bar"+| |
| | } | |
FROM http_post('https://httpbin.org/anything?foo=bar','payload','text/plain');
status | data | args | url | method
--------+-----------+------------------+----------------------------------------+--------
200 | "payload" | { +| "https://httpbin.org/anything?foo=bar" | "POST"
| | "foo": "bar"+| |
| | } | |
(1 row)

-- HEAD
SELECT *
FROM (
SELECT (unnest(headers)).*
FROM http_head('http://httpbin.org/response-headers?Abcde=abcde')
FROM http_head('https://httpbin.org/response-headers?Abcde=abcde')
) a
WHERE field = 'Abcde';
field | value
Expand All @@ -122,18 +122,18 @@ WHERE field = 'Abcde';
SELECT status,
content::json->'args' AS args,
content::json->'url' AS url
FROM http_get('http://httpbin.org/redirect-to?url=http%3A%2F%2Fhttpbin%2Eorg%2Fget%3Ffoo%3Dbar');
status | args | url
--------+------------------+----------------------------------
200 | { +| "http://httpbin.org/get?foo=bar"
FROM http_get('https://httpbin.org/redirect-to?url=http%3A%2F%2Fhttpbin%2Eorg%2Fget%3Ffoo%3Dbar');
status | args | url
--------+------------------+-----------------------------------
200 | { +| "https://httpbin.org/get?foo=bar"
| "foo": "bar"+|
| } |
(1 row)

-- Request image
WITH
http AS (
SELECT * FROM http_get('http://httpbin.org/image/png')
SELECT * FROM http_get('https://httpbin.org/image/png')
),
headers AS (
SELECT (unnest(headers)).* FROM http
Expand All @@ -157,10 +157,10 @@ SELECT http_set_curlopt('CURLOPT_PROXY', '127.0.0.1');
(1 row)

-- Error because proxy is not there
SELECT status FROM http_get('http://httpbin.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
ERROR: Failed to connect to 127.0.0.1 port 1080: Connection refused
-- Still an error
SELECT status FROM http_get('http://httpbin.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
ERROR: Failed to connect to 127.0.0.1 port 1080: Connection refused
SELECT http_reset_curlopt();
http_reset_curlopt
Expand All @@ -169,13 +169,13 @@ SELECT http_reset_curlopt();
(1 row)

-- Now it should work
SELECT status FROM http_get('http://httpbin.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
status
--------
555
(1 row)

-- Alter the default timeout and then run a query that is longer than
-- Alter the default timeout and then run a query that is longer than
-- the default (5s), but shorter than the new timeout
SELECT http_set_curlopt('CURLOPT_TIMEOUT_MS', '10000');
http_set_curlopt
Expand Down
9 changes: 8 additions & 1 deletion http.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,16 @@ typname_get_tupledesc(const char *extname, const char *typname)
foreach(l, fetch_search_path(true))
{
Oid typnamespace = lfirst_oid(l);
Oid typoid = GetSysCacheOid2(TYPENAMENSP,

#if PG_VERSION_NUM >= 120000
Oid typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
PointerGetDatum(typname),
ObjectIdGetDatum(typnamespace));
#else
Oid typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
PointerGetDatum(typname),
ObjectIdGetDatum(typnamespace));
#endif

if ( OidIsValid(typoid) )
{
Expand Down
30 changes: 15 additions & 15 deletions sql/http.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ SELECT http_set_curlopt('CURLOPT_TIMEOUT', '10');

-- Status code
SELECT status
FROM http_get('http://httpbin.org/status/202');
FROM http_get('https://httpbin.org/status/202');

-- Headers
SELECT *
FROM (
SELECT (unnest(headers)).*
FROM http_get('http://httpbin.org/response-headers?Abcde=abcde')
FROM http_get('https://httpbin.org/response-headers?Abcde=abcde')
) a
WHERE field = 'Abcde';

Expand All @@ -20,65 +20,65 @@ SELECT status,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_get('http://httpbin.org/anything?foo=bar');
FROM http_get('https://httpbin.org/anything?foo=bar');

-- GET with data
SELECT status,
content::json->'args' as args,
content::json->>'data' as data,
content::json->'url' as url,
content::json->'method' as method
from http(('GET', 'http://httpbin.org/anything', NULL, 'application/json', '{"search": "toto"}'));
from http(('GET', 'https://httpbin.org/anything', NULL, 'application/json', '{"search": "toto"}'));

-- DELETE
SELECT status,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_delete('http://httpbin.org/anything?foo=bar');
FROM http_delete('https://httpbin.org/anything?foo=bar');

-- PUT
SELECT status,
content::json->'data' AS data,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_put('http://httpbin.org/anything?foo=bar','payload','text/plain');
FROM http_put('https://httpbin.org/anything?foo=bar','payload','text/plain');

-- PATCH
SELECT status,
content::json->'data' AS data,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_patch('http://httpbin.org/anything?foo=bar','{"this":"that"}','application/json');
FROM http_patch('https://httpbin.org/anything?foo=bar','{"this":"that"}','application/json');

-- POST
SELECT status,
content::json->'data' AS data,
content::json->'args' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_post('http://httpbin.org/anything?foo=bar','payload','text/plain');
FROM http_post('https://httpbin.org/anything?foo=bar','payload','text/plain');

-- HEAD
SELECT *
FROM (
SELECT (unnest(headers)).*
FROM http_head('http://httpbin.org/response-headers?Abcde=abcde')
FROM http_head('https://httpbin.org/response-headers?Abcde=abcde')
) a
WHERE field = 'Abcde';

-- Follow redirect
SELECT status,
content::json->'args' AS args,
content::json->'url' AS url
FROM http_get('http://httpbin.org/redirect-to?url=http%3A%2F%2Fhttpbin%2Eorg%2Fget%3Ffoo%3Dbar');
FROM http_get('https://httpbin.org/redirect-to?url=http%3A%2F%2Fhttpbin%2Eorg%2Fget%3Ffoo%3Dbar');

-- Request image
WITH
http AS (
SELECT * FROM http_get('http://httpbin.org/image/png')
SELECT * FROM http_get('https://httpbin.org/image/png')
),
headers AS (
SELECT (unnest(headers)).* FROM http
Expand All @@ -93,14 +93,14 @@ WHERE field = 'Content-Length';
-- Alter options and and reset them and throw errors
SELECT http_set_curlopt('CURLOPT_PROXY', '127.0.0.1');
-- Error because proxy is not there
SELECT status FROM http_get('http://httpbin.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
-- Still an error
SELECT status FROM http_get('http://httpbin.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
SELECT http_reset_curlopt();
-- Now it should work
SELECT status FROM http_get('http://httpbin.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');

-- Alter the default timeout and then run a query that is longer than
-- Alter the default timeout and then run a query that is longer than
-- the default (5s), but shorter than the new timeout
SELECT http_set_curlopt('CURLOPT_TIMEOUT_MS', '10000');
SELECT status FROM http_get('http://httpstat.us/200?sleep=7000');

0 comments on commit 9fd8e9c

Please # to comment.