libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] largepost.c reset connection when file already exists


From: Vitaliy T
Subject: [libmicrohttpd] largepost.c reset connection when file already exists
Date: Sat, 11 Mar 2017 07:09:22 +0300

Hi,

I have started using libmicrohttpd and I am experienced a problem with
the largepost.c example.

If you have uploaded a file and later try to upload it again you will get the error:
    Internal application error, closing connection.

It is a bit hard to debug (or just I am lack of such expirience), but as far I can tell
the overall picture looks like that:

1. answer_to_connection() -> MHD_post_process().
2. MHD_post_process() -> iterate_post().
3. iterate_post() returns MHD_NO because the file exists.
4. MHD_post_process() returns MHD_NO too.
5. now we call send_page(connection, postprocerror, MHD_HTTP_BAD_REQUEST):

if (MHD_post_process (con_info->postprocessor, upload_data, *upload_data_size)
    != MHD_YES)
{
    return send_page (connection,
        postprocerror, MHD_HTTP_BAD_REQUEST);
}

6. inside of send_page()  the MHD_queue_response() returns MHD_NO (why???).
7. the same status returned by answer_to_connection().
8. answer_to_connection() in the end calls process_request_body() [connection.c]
and the next code prints out the error above:

/**
 * Call the handler of the application for this
 * connection.  Handles chunking of the upload
 * as well as normal uploads.
 *
 * @param connection connection we're processing
 */
static void
process_request_body (struct MHD_Connection *connection)
{
...

      if (MHD_NO ==
          connection->daemon->default_handler (connection->daemon->default_handler_cls,
                                               connection,
                                               connection->url,
                                               connection->method,
                                               connection->version,
                                               buffer_head,
                                               &processed,
                                               &connection->client_context))
        {
          /* serious internal error, close connection */
      CONNECTION_CLOSE_ERROR (connection,
                  "Internal application error, closing connection.\n");
          return;
        }


I found out why MHD_queue_response() returns MHD_NO:

int
MHD_queue_response (struct MHD_Connection *connection,
                    unsigned int status_code,
                    struct MHD_Response *response)
{
  struct MHD_Daemon *daemon;

  if ( (NULL == connection) ||
       (NULL == response) ||
       (NULL != connection->response) ||
       ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) &&
     (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) )
    return MHD_NO;

The connection->state is set to MHD_CONNECTION_CONTINUE_SENT.

Any thoughts how to fix this?

Tested on:
1. GNU/Linux, libmicrohttp 0.9.50
2. Window 7 64-bit, libmicrohttp 0.9.51, 32-bit (downloaded from ftp).
3. Window 7 64-bit, libmicrohttp 0.9.52, 32-bit built under MSVS 2015.

Thanks!

--
With Best Regards,
Vitaliy V. Tokarev

reply via email to

[Prev in Thread] Current Thread [Next in Thread]