Skip to content

Commit b32fe53

Browse files
committed
fix: pg_net doesn't support redirects
1 parent e0bf4e5 commit b32fe53

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

nix/nginx/conf/custom.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ location /delete {
3737
}
3838
echo_duplicate 1 $echo_client_request_headers$is_args$query_string;
3939
}
40+
41+
location /redirect_me {
42+
return 301 /to_here;
43+
}
44+
45+
location /to_here {
46+
echo 'I got redirected';
47+
}

src/worker.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static CURLMcode init(CURLM *cm, char *method, char *url, int timeout_millisecon
147147
curl_easy_setopt(eh, CURLOPT_HTTPHEADER, cdata->request_headers);
148148
curl_easy_setopt(eh, CURLOPT_TIMEOUT_MS, timeout_milliseconds);
149149
curl_easy_setopt(eh, CURLOPT_PRIVATE, cdata);
150+
curl_easy_setopt(eh, CURLOPT_FOLLOWLOCATION, true);
150151
if (log_min_messages <= DEBUG1)
151152
curl_easy_setopt(eh, CURLOPT_VERBOSE, 1L);
152153
curl_easy_setopt(eh, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);

test/test_http_get_collect.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,28 @@ def test_http_get_responses_have_different_created_times(sess):
124124
)).scalar()
125125

126126
assert count == 3
127+
128+
def test_http_get_collect_with_redirect(sess):
129+
"""Follows a redirect and collects a response"""
130+
131+
# Create a request
132+
(request_id,) = sess.execute(text(
133+
"""
134+
select net.http_get('http://localhost:8080/redirect_me');
135+
"""
136+
)).fetchone()
137+
138+
# Commit so background worker can start
139+
sess.commit()
140+
141+
# Collect the response, waiting as needed
142+
response = sess.execute(text(
143+
"""
144+
select * from net._http_collect_response(:request_id, async:=false);
145+
"""
146+
),
147+
{"request_id": request_id},
148+
).fetchone()
149+
150+
assert response is not None
151+
assert "I got redirected" in response[2]

0 commit comments

Comments
 (0)