Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ else
endif

EXTENSION = pg_net
EXTVERSION = 0.20.0
EXTVERSION = 0.20.1

DATA = $(wildcard sql/*--*.sql)

Expand Down
1 change: 1 addition & 0 deletions sql/pg_net--0.20.0--0.20.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- no SQL changes in 0.20.1
15 changes: 15 additions & 0 deletions src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
list = new_list; \
} while (0)

// curl_url_strerror is available starting from libcurl 7.80.0
#define EREPORT_CURL_URL_SET(hdl, part, str, flags) \
do { \
CURLUcode rc = curl_url_set(hdl, part, str, flags); \
if (rc != CURLUE_OK) \
ereport(ERROR, errmsg("invalid URL \"%s\": %s", str, curl_url_strerror(rc))); \
} while (0)

#define EREPORT_CURL_URL_GET(hdl, part, out, flags, value) \
do { \
CURLUcode rc = curl_url_get(hdl, part, out, flags); \
if (rc != CURLUE_OK) \
ereport(ERROR, errmsg("failed to encode URL \"%s\": %s", value, curl_url_strerror(rc))); \
} while (0)

#define EREPORT_NULL_ATTR(tupIsNull, attr) \
do { \
if (tupIsNull) ereport(ERROR, errmsg("%s cannot be null", #attr)); \
Expand Down
2 changes: 1 addition & 1 deletion src/event.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef EVENT_H
#define EVENT_H

#include <curl/multi.h>
#include "curl_prelude.h"

#include "core.h"

Expand Down
19 changes: 5 additions & 14 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "curl_prelude.h"

#include "errors.h"
#include "util.h"

PG_FUNCTION_INFO_V1(_urlencode_string);
Expand Down Expand Up @@ -33,30 +34,20 @@ Datum _encode_url_with_params_array(PG_FUNCTION_ARGS) {
bool isnull;
char *param;

CURLU *h = curl_url();
CURLUcode rc = curl_url_set(h, CURLUPART_URL, url, 0);
if (rc != CURLUE_OK) {
// TODO: Use curl_url_strerror once released.
elog(ERROR, "%s", curl_easy_strerror((CURLcode)rc));
}
CURLU *h = curl_url();
EREPORT_CURL_URL_SET(h, CURLUPART_URL, url, 0);

iterator = array_create_iterator(params, 0, NULL);
while (array_iterate(iterator, &value, &isnull)) {
if (isnull) continue;

param = TextDatumGetCString(value);
rc = curl_url_set(h, CURLUPART_QUERY, param, CURLU_APPENDQUERY);
if (rc != CURLUE_OK) {
elog(ERROR, "curl_url returned: %d", rc);
}
EREPORT_CURL_URL_SET(h, CURLUPART_QUERY, param, CURLU_APPENDQUERY);
pfree(param);
}
array_free_iterator(iterator);

rc = curl_url_get(h, CURLUPART_URL, &full_url, 0);
if (rc != CURLUE_OK) {
elog(ERROR, "curl_url returned: %d", rc);
}
EREPORT_CURL_URL_GET(h, CURLUPART_URL, &full_url, 0, url);

pfree(url);
curl_url_cleanup(h);
Expand Down
15 changes: 14 additions & 1 deletion test/test_http_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@ def test_get_bad_url(sess):
"""
))

assert r"resolve proxy name" in str(execinfo)
assert 'Unsupported URL scheme' in str(execinfo.value)


def test_http_get_rejects_relative_url(sess):
"""net.http_get with a correct error when given a relative url"""

with pytest.raises(Exception) as execinfo:
sess.execute(text(
"""
select net.http_get('/malformed_url');
"""
))

assert 'invalid URL "/malformed_url"' in str(execinfo.value)


def test_bad_post(sess):
Expand Down