POST times out/resets connection

30 views
Skip to first unread message

jesusw...@gmail.com

unread,
Jun 7, 2014, 11:19:30 PM6/7/14
to onio...@coralbits.com
I have some code using libonion.  Using simple GET requests and queries, it works fine.  However, I have one page that is POSTing a simple form.  When it posts, the browser spins for about 30-45 seconds before getting a Connection Reset.  In my logs, I never see an INFO response message for the requested page.  If I initiate a GET request on the same URL/page, it responds just fine (except that I can't get any POST data).  I have the syslog() line in the handler, but I never see the log hit my syslog.  I suspect I'm not setting up the handler properly.


My code looks like this:

/**
 * @short adds a new user to the system
 */
onion_connection_status userAdd_handler(void *none, onion_request *req, onion_response *res) {
    char temp[1024];

    syslog(LOG_ERR, "userAdd_handler\n");

    if (onion_request_get_flags(req)&OR_HEAD){
        onion_response_write_headers(res);
        return OCS_PROCESSED;
    }

    onion_dict *post = onion_request_get_post_dict(req);
    // alternatively onion_dict *post = onion_dict_from_json(json_data);

    onion_block *json = onion_dict_to_json(post);
    printf("POST DATA: %s\n", onion_block_data(json));
    onion_block_free(json);

    onion_dict *out = onion_dict_new();
    getUsersTable(out);

    onion_response_set_code(res, HTTP_CREATED);
    return onion_shortcut_redirect("/user", req, res);
}

static void *webInterfaceThread(void *data) {
    onion *server=onion_new(O_ONE_LOOP);

    onion_url *url = onion_root_url(server);
    onion_set_hostname(server, "0.0.0.0");
    onion_set_port(server, "8120");

    ONION_INFO("Listening at http://0.0.0.0:8120");

    onion_url_add(url, "camImage.png", (void*)camImage_handler);
    onion_url_add(url, "accessLog.json", (void*)accessLog_handler);
    onion_url_add(url, "accessTable.json", (void*)accessTable_handler);
    onion_url_add(url, "userTable.json", (void*)userTable_handler);

    onion_url_add(url, "testEmail.smtp", (void*)sendEmail_handler);

    onion_url_add_static(url, "user",
        "<html><body><form method=POST action=\"/addUser\">"
        "<textarea></textarea><input type=\"submit\">"
        "</form></body></html>", HTTP_OK);
    onion_url_add(url, "addUser", (void*)userAdd_handler);

    onion_listen(server);
    onion_free(server);

    return 0;
}


Any suggestions?


jesusw...@gmail.com

unread,
Jun 8, 2014, 1:24:45 PM6/8/14
to onio...@coralbits.com, jesusw...@gmail.com
After troubleshooting with tcpdump, it turns out my <textarea> tag had problems.  Changing it to an <input> tag worked.  I suspect there maybe an issue with a zero-length POSTs.

--Kyle
Reply all
Reply to author
Forward
0 new messages