Skip to content

Commit

Permalink
Move back to httpbin.org
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Jan 9, 2024
1 parent 5e72b80 commit 7a6a22c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
58 changes: 29 additions & 29 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('https://httpbun.org/status/202');
FROM http_get('https://httpbin.org/status/202');
status
--------
202
Expand All @@ -18,7 +18,7 @@ FROM http_get('https://httpbun.org/status/202');
SELECT lower(field) AS field, value
FROM (
SELECT (unnest(headers)).*
FROM http_get('https://httpbun.org/response-headers?Abcde=abcde')
FROM http_get('https://httpbin.org/response-headers?Abcde=abcde')
) a
WHERE field ILIKE 'Abcde';
field | value
Expand All @@ -31,21 +31,21 @@ SELECT status,
content::json->'args'->>'foo' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_get('https://httpbun.org/anything?foo=bar');
FROM http_get('https://httpbin.org/anything?foo=bar');
status | args | url | method
--------+------+----------------------------------------+--------
200 | bar | "https://httpbun.org/anything?foo=bar" | "GET"
200 | bar | "https://httpbin.org/anything?foo=bar" | "GET"
(1 row)

-- GET with data
SELECT status,
content::json->'args'->>'this' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_get('https://httpbun.org/anything', jsonb_build_object('this', 'that'));
FROM http_get('https://httpbin.org/anything', jsonb_build_object('this', 'that'));
status | args | url | method
--------+------+------------------------------------------+--------
200 | that | "https://httpbun.org/anything?this=that" | "GET"
200 | that | "https://httpbin.org/anything?this=that" | "GET"
(1 row)

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

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

-- DELETE with payload
Expand All @@ -77,10 +77,10 @@ content::json->'args'->>'foo' AS args,
content::json->'url' AS url,
content::json->'method' AS method,
content::json->'data' AS data
FROM http_delete('https://httpbun.org/anything?foo=bar', 'payload', 'text/plain');
FROM http_delete('https://httpbin.org/anything?foo=bar', 'payload', 'text/plain');
status | args | url | method | data
--------+------+----------------------------------------+----------+-----------
200 | bar | "https://httpbun.org/anything?foo=bar" | "DELETE" | "payload"
200 | bar | "https://httpbin.org/anything?foo=bar" | "DELETE" | "payload"
(1 row)

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

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

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

-- POST with json data
SELECT status,
content::json->'form'->>'this' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_post('https://httpbun.org/anything', jsonb_build_object('this', 'that'));
FROM http_post('https://httpbin.org/anything', jsonb_build_object('this', 'that'));
status | args | url | method
--------+------+--------------------------------+--------
200 | that | "https://httpbun.org/anything" | "POST"
200 | that | "https://httpbin.org/anything" | "POST"
(1 row)

-- POST with data
Expand All @@ -136,17 +136,17 @@ content::json->'form'->>'key1' AS key1,
content::json->'form'->>'key2' AS key2,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_post('https://httpbun.org/anything', 'key1=value1&key2=value2','application/x-www-form-urlencoded');
FROM http_post('https://httpbin.org/anything', 'key1=value1&key2=value2','application/x-www-form-urlencoded');
status | key1 | key2 | url | method
--------+--------+--------+--------------------------------+--------
200 | value1 | value2 | "https://httpbun.org/anything" | "POST"
200 | value1 | value2 | "https://httpbin.org/anything" | "POST"
(1 row)

-- HEAD
SELECT lower(field) AS field, value
FROM (
SELECT (unnest(headers)).*
FROM http_head('https://httpbun.org/response-headers?Abcde=abcde')
FROM http_head('https://httpbin.org/response-headers?Abcde=abcde')
) a
WHERE field ILIKE 'Abcde';
field | value
Expand All @@ -157,10 +157,10 @@ WHERE field ILIKE 'Abcde';
-- Follow redirect
SELECT status,
content::json->'url' AS url
FROM http_get('https://httpbun.org/redirect-to?url=get');
FROM http_get('https://httpbin.org/redirect-to?url=get');
status | url
--------+---------------------------
200 | "https://httpbun.org/get"
200 | "https://httpbin.org/get"
(1 row)

-- Request image
Expand Down Expand Up @@ -191,7 +191,7 @@ SELECT http_set_curlopt('CURLOPT_PROXY', '127.0.0.1');
-- Error because proxy is not there
DO $$
BEGIN
SELECT status FROM http_get('https://httpbun.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
EXCEPTION
WHEN OTHERS THEN
RAISE WARNING 'Failed to connect';
Expand All @@ -201,7 +201,7 @@ WARNING: Failed to connect
-- Still an error
DO $$
BEGIN
SELECT status FROM http_get('https://httpbun.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
EXCEPTION
WHEN OTHERS THEN
RAISE WARNING 'Failed to connect';
Expand All @@ -216,7 +216,7 @@ SELECT http_reset_curlopt();
(1 row)

-- Now it should work
SELECT status FROM http_get('https://httpbun.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
status
--------
555
Expand All @@ -230,7 +230,7 @@ SELECT http_set_curlopt('CURLOPT_TIMEOUT_MS', '10000');
t
(1 row)

SELECT status FROM http_get('https://httpbun.org/delay/7');
SELECT status FROM http_get('https://httpbin.org/delay/7');
status
--------
200
Expand Down
36 changes: 18 additions & 18 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('https://httpbun.org/status/202');
FROM http_get('https://httpbin.org/status/202');

-- Headers
SELECT lower(field) AS field, value
FROM (
SELECT (unnest(headers)).*
FROM http_get('https://httpbun.org/response-headers?Abcde=abcde')
FROM http_get('https://httpbin.org/response-headers?Abcde=abcde')
) a
WHERE field ILIKE 'Abcde';

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

-- GET with data
SELECT status,
content::json->'args'->>'this' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_get('https://httpbun.org/anything', jsonb_build_object('this', 'that'));
FROM http_get('https://httpbin.org/anything', jsonb_build_object('this', 'that'));

-- 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', 'https://httpbun.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'->>'foo' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_delete('https://httpbun.org/anything?foo=bar');
FROM http_delete('https://httpbin.org/anything?foo=bar');

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

-- PUT
SELECT status,
content::json->'data' AS data,
content::json->'args'->>'foo' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_put('https://httpbun.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'->>'foo' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_patch('https://httpbun.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'->>'foo' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_post('https://httpbun.org/anything?foo=bar','payload','text/plain');
FROM http_post('https://httpbin.org/anything?foo=bar','payload','text/plain');

-- POST with json data
SELECT status,
content::json->'form'->>'this' AS args,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_post('https://httpbun.org/anything', jsonb_build_object('this', 'that'));
FROM http_post('https://httpbin.org/anything', jsonb_build_object('this', 'that'));

-- POST with data
SELECT status,
content::json->'form'->>'key1' AS key1,
content::json->'form'->>'key2' AS key2,
content::json->'url' AS url,
content::json->'method' AS method
FROM http_post('https://httpbun.org/anything', 'key1=value1&key2=value2','application/x-www-form-urlencoded');
FROM http_post('https://httpbin.org/anything', 'key1=value1&key2=value2','application/x-www-form-urlencoded');

-- HEAD
SELECT lower(field) AS field, value
FROM (
SELECT (unnest(headers)).*
FROM http_head('https://httpbun.org/response-headers?Abcde=abcde')
FROM http_head('https://httpbin.org/response-headers?Abcde=abcde')
) a
WHERE field ILIKE 'Abcde';

-- Follow redirect
SELECT status,
content::json->'url' AS url
FROM http_get('https://httpbun.org/redirect-to?url=get');
FROM http_get('https://httpbin.org/redirect-to?url=get');

-- Request image
WITH
Expand All @@ -123,7 +123,7 @@ SELECT http_set_curlopt('CURLOPT_PROXY', '127.0.0.1');
-- Error because proxy is not there
DO $$
BEGIN
SELECT status FROM http_get('https://httpbun.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
EXCEPTION
WHEN OTHERS THEN
RAISE WARNING 'Failed to connect';
Expand All @@ -132,7 +132,7 @@ $$;
-- Still an error
DO $$
BEGIN
SELECT status FROM http_get('https://httpbun.org/status/555');
SELECT status FROM http_get('https://httpbin.org/status/555');
EXCEPTION
WHEN OTHERS THEN
RAISE WARNING 'Failed to connect';
Expand All @@ -141,9 +141,9 @@ $$;
-- Reset options
SELECT http_reset_curlopt();
-- Now it should work
SELECT status FROM http_get('https://httpbun.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
-- the default (5s), but shorter than the new timeout
SELECT http_set_curlopt('CURLOPT_TIMEOUT_MS', '10000');
SELECT status FROM http_get('https://httpbun.org/delay/7');
SELECT status FROM http_get('https://httpbin.org/delay/7');

0 comments on commit 7a6a22c

Please sign in to comment.