@@ -14,6 +14,8 @@ create table net.http_request_queue(
14
14
url text not null ,
15
15
headers jsonb not null ,
16
16
body bytea ,
17
+ -- TODO: respect this
18
+ timeout_milliseconds int not null ,
17
19
created timestamptz not null default now()
18
20
);
19
21
@@ -91,7 +93,9 @@ create or replace function net.http_get(
91
93
-- key/value pairs to be url encoded and appended to the `url`
92
94
params jsonb default ' {}' ::jsonb,
93
95
-- key/values to be included in request headers
94
- headers jsonb default ' {}' ::jsonb
96
+ headers jsonb default ' {}' ::jsonb,
97
+ -- the maximum number of milliseconds the request may take before being cancelled
98
+ timeout_milliseconds int default 1000
95
99
)
96
100
-- request_id reference
97
101
returns bigint
@@ -109,11 +113,12 @@ begin
109
113
from jsonb_each_text(params);
110
114
111
115
-- Add to the request queue
112
- insert into net .http_request_queue (method, url, headers)
116
+ insert into net .http_request_queue (method, url, headers, timeout_milliseconds )
113
117
values (
114
118
' GET' ,
115
119
net ._encode_url_with_params_array (url, params_array),
116
- headers
120
+ headers,
121
+ timeout_milliseconds
117
122
)
118
123
returning id
119
124
into request_id;
@@ -132,7 +137,9 @@ create or replace function net.http_post(
132
137
-- key/value pairs to be url encoded and appended to the `url`
133
138
params jsonb default ' {}' ::jsonb,
134
139
-- key/values to be included in request headers
135
- headers jsonb default ' {"Content-Type": "application/json"}' ::jsonb
140
+ headers jsonb default ' {"Content-Type": "application/json"}' ::jsonb,
141
+ -- the maximum number of milliseconds the request may take before being cancelled
142
+ timeout_milliseconds int DEFAULT 1000
136
143
)
137
144
-- request_id reference
138
145
returns bigint
@@ -180,12 +187,13 @@ begin
180
187
jsonb_each_text(params);
181
188
182
189
-- Add to the request queue
183
- insert into net .http_request_queue (method, url, headers, body)
190
+ insert into net .http_request_queue (method, url, headers, body, timeout_milliseconds )
184
191
values (
185
192
' POST' ,
186
193
net ._encode_url_with_params_array (url, params_array),
187
194
headers,
188
- body::text ::bytea
195
+ body::text ::bytea ,
196
+ timeout_milliseconds
189
197
)
190
198
returning id
191
199
into request_id;
0 commit comments