|
| 1 | +-- Test for http extension |
| 2 | +-- Basic HTTP functionality tests |
| 3 | +-- Test basic HTTP GET request |
| 4 | +SELECT status FROM http_get('http://httpbingo.org/get'); |
| 5 | + status |
| 6 | +-------- |
| 7 | + 200 |
| 8 | +(1 row) |
| 9 | + |
| 10 | +-- Test HTTP GET with headers |
| 11 | +SELECT status, content_type |
| 12 | +FROM http(( |
| 13 | + 'GET', |
| 14 | + 'http://httpbingo.org/headers', |
| 15 | + ARRAY[http_header('User-Agent', 'pg_http_test')], |
| 16 | + NULL, |
| 17 | + NULL |
| 18 | +)::http_request); |
| 19 | + status | content_type |
| 20 | +--------+--------------------------------- |
| 21 | + 200 | application/json; charset=utf-8 |
| 22 | +(1 row) |
| 23 | + |
| 24 | +-- Test HTTP POST request with JSON body |
| 25 | +SELECT status FROM http_post( |
| 26 | + 'http://httpbingo.org/post', |
| 27 | + '{"test": "data"}', |
| 28 | + 'application/json' |
| 29 | +); |
| 30 | + status |
| 31 | +-------- |
| 32 | + 200 |
| 33 | +(1 row) |
| 34 | + |
| 35 | +-- Test HTTP PUT request |
| 36 | +SELECT status FROM http_put( |
| 37 | + 'http://httpbingo.org/put', |
| 38 | + '{"update": "data"}', |
| 39 | + 'application/json' |
| 40 | +); |
| 41 | + status |
| 42 | +-------- |
| 43 | + 200 |
| 44 | +(1 row) |
| 45 | + |
| 46 | +-- Test HTTP DELETE request |
| 47 | +SELECT status FROM http_delete('http://httpbingo.org/delete'); |
| 48 | + status |
| 49 | +-------- |
| 50 | + 200 |
| 51 | +(1 row) |
| 52 | + |
| 53 | +-- Test HTTP PATCH request |
| 54 | +SELECT status FROM http_patch( |
| 55 | + 'http://httpbingo.org/patch', |
| 56 | + '{"patch": "data"}', |
| 57 | + 'application/json' |
| 58 | +); |
| 59 | + status |
| 60 | +-------- |
| 61 | + 200 |
| 62 | +(1 row) |
| 63 | + |
| 64 | +-- Test HTTP HEAD request |
| 65 | +SELECT status FROM http_head('http://httpbingo.org/get'); |
| 66 | + status |
| 67 | +-------- |
| 68 | + 200 |
| 69 | +(1 row) |
| 70 | + |
| 71 | +-- Test response headers parsing |
| 72 | +WITH response AS ( |
| 73 | + SELECT * FROM http_get('http://httpbingo.org/response-headers?Content-Type=text/plain') |
| 74 | +) |
| 75 | +SELECT |
| 76 | + status, |
| 77 | + content_type, |
| 78 | + headers IS NOT NULL as has_headers |
| 79 | +FROM response; |
| 80 | + status | content_type | has_headers |
| 81 | +--------+--------------+------------- |
| 82 | + 200 | text/plain | t |
| 83 | +(1 row) |
| 84 | + |
| 85 | +-- Test timeout handling (using a delay endpoint) |
| 86 | +-- This should complete successfully with reasonable timeout |
| 87 | +SELECT status FROM http(( |
| 88 | + 'GET', |
| 89 | + 'http://httpbingo.org/delay/1', |
| 90 | + ARRAY[]::http_header[], |
| 91 | + 'application/json', |
| 92 | + 2000 -- 2 second timeout |
| 93 | +)::http_request); |
| 94 | + status |
| 95 | +-------- |
| 96 | + 200 |
| 97 | +(1 row) |
| 98 | + |
| 99 | +-- Test URL encoding |
| 100 | +SELECT status FROM http_get('http://httpbingo.org/anything?param=value%20with%20spaces&another=123'); |
| 101 | + status |
| 102 | +-------- |
| 103 | + 200 |
| 104 | +(1 row) |
| 105 | + |
0 commit comments