Skip to content

Commit

Permalink
Remove assert if json is too big for jsonencoder
Browse files Browse the repository at this point in the history
  • Loading branch information
nikobockerman committed Jul 13, 2020
1 parent 0b44e30 commit 0e60cee
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/jsonop.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,32 @@ void jsonop_unregister_callback(jsonop_t *op)

FSTRACE_DECL(ASYNCHTTP_JSONOP_CREATE,
"UID=%64u PTR=%p ASYNC=%p CLIENT=%p URI=%s ENCODER=%p");
FSTRACE_DECL(ASYNCHTTP_JSONOP_CREATE_FAIL_TOO_LARGE,
"CLIENT=%p URI=%s ENCODER=%p");

jsonop_t *jsonop_make_request(async_t *async, http_client_t *client,
const char *uri, json_thing_t *request_body)
{
http_op_t *http_op = http_client_make_request(client, "POST", uri);
if (!http_op)
return NULL;
jsonencoder_t *encoder = json_encode(async, request_body);
ssize_t size = jsonencoder_size(encoder);
if (size < 0) {
FSTRACE(ASYNCHTTP_JSONOP_CREATE_FAIL_TOO_LARGE, client, uri, encoder);
jsonencoder_close(encoder);
http_op_close(http_op);
return NULL;
}

jsonop_t *op = fsalloc(sizeof *op);
op->async = async;
op->uid = fstrace_get_unique_id();
op->callback = NULL_ACTION_1;
op->http_op = http_op;
http_env_add_header(jsonop_get_request_envelope(op),
"Content-type", "application/json");
jsonencoder_t *encoder = json_encode(op->async, request_body);
FSTRACE(ASYNCHTTP_JSONOP_CREATE, op->uid, op, async, client, uri, encoder);
ssize_t size = jsonencoder_size(encoder);
assert(size >= 0);
http_op_set_content(op->http_op, size,
jsonencoder_as_bytestream_1(encoder));
op->state = JSONOP_REQUESTED;
Expand Down

0 comments on commit 0e60cee

Please sign in to comment.