libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] largepost.c reset connection when file already exist


From: Christian Grothoff
Subject: Re: [libmicrohttpd] largepost.c reset connection when file already exists
Date: Sat, 11 Mar 2017 12:41:11 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

Hi Vitaliy,

The example indeed had an issue in that it was trying to queue a
response during the upload (instead of at the end).

Fixed in 15a2570f..740a46dd

Happy hacking!

Christian

On 03/11/2017 05:09 AM, Vitaliy T wrote:
> 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!
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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