Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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 sql/pg_net--0.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ create table net._http_response(
status_code integer,
content_type text,
headers jsonb,
content text,
body bytea,
timed_out bool,
error_msg text
);
Expand Down
20 changes: 13 additions & 7 deletions src/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ body_cb(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
StringInfo si = (StringInfo)userp;
appendBinaryStringInfo(si, (const char*)contents, (int)realsize);
appendBinaryStringInfoNT(si, (const char*)contents, (int)realsize);
return realsize;
}

Expand Down Expand Up @@ -353,6 +353,8 @@ worker_main(Datum main_arg)
false, 1) != SPI_OK_INSERT)
{
elog(ERROR, "SPI_exec failed: %s", query_insert_response_bad.data);


}
} else {
int argCount = 6;
Expand All @@ -362,6 +364,7 @@ worker_main(Datum main_arg)
CurlData *cdata = NULL;
char *contentType = NULL;
bool timedOut = false;
bytea *body_data = NULL;

curl_easy_getinfo(eh, CURLINFO_RESPONSE_CODE, &http_status_code);
curl_easy_getinfo(eh, CURLINFO_CONTENT_TYPE, &contentType);
Expand All @@ -379,12 +382,14 @@ worker_main(Datum main_arg)
argValues[1] = Int32GetDatum(http_status_code);
nulls[1] = ' ';

argTypes[2] = CSTRINGOID;
argValues[2] = CStringGetDatum(cdata->body->data);
if(cdata->body->data[0] == '\0')
nulls[2] = 'n';
else
nulls[2] = ' ';
argTypes[2] = BYTEAOID;

body_data = (bytea *) palloc(cdata->body->len + VARHDRSZ);
SET_VARSIZE(body_data, cdata->body->len + VARHDRSZ);
memcpy(VARDATA(body_data), cdata->body->data, cdata->body->len);
Comment on lines +387 to +389
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of converting a char* to bytea is done in many parts of the postgres code(example).


argValues[2] = PointerGetDatum(body_data);
nulls[2] = ' ';

argTypes[3] = JSONBOID;
argValues[3] = JsonbPGetDatum(JsonbValueToJsonb(pushJsonbValue(&cdata->headers, WJB_END_OBJECT, NULL)));
Expand All @@ -409,6 +414,7 @@ worker_main(Datum main_arg)

pfree(cdata->body->data);
pfree(cdata->body);
pfree(body_data);
}

curl_multi_remove_handle(cm, eh);
Expand Down