cesanta/fossa

ns_connect_http() does not send post data

kkutsner opened this issue · 2 comments

I discovered that if I'm passing some post data to ns_connect_http() it actually writes only headers but not the post data itself. I'm pretty sure this helper could send the data itself, not only headers.Am I missing something?

cpq commented

Could you paste your code please?

I'm trying to make a call:
struct ns_connection* connection = ns_connect_http(&mgr, http_get_handler, url, 0, data);
In particular call data is non-empty string. There is simple handler to show what events are handled

static void http_get_handler(struct ns_connection *nc, int ev, void *ev_data)
{
  struct http_message *hm = (struct http_message *) ev_data;
  http_get_context* context = nc->user_data;
  switch (ev)
  {
  case NS_CONNECT:
    if (*(int *)ev_data != 0)
    {
    //...
      context->is_error = true;
    }
    break;
  case NS_HTTP_REPLY:
    nc->flags |= NSF_CLOSE_IMMEDIATELY;
    //...
    break;
  default:
    break;
  }

}

There is very simple polling loop:

if (connection)
  {
    connection->user_data = cntx;

    // set default timeout if user's timeout is not specified
    if (!timeout)
    {
      timeout = 30 * 1000;
    }

    // process downloading until result or timeout
    while (!cntx->is_error && timeout > 0 && mgr.active_connections)
    {
      ns_mgr_poll(&mgr, 1000);
      timeout -= 1000;
    }

    // check timeout status
    if (timeout <= 0)
    {
      cntx->is_error = true;
...
    }
  }

Is it assumed that data should be sent manually (by implementing NS_SEND handler) only when connection is established?