Karlson2k / libmicrohttpd

GNU libmicrohttpd repository unofficial mirror on GitHub
https://www.gnu.org/software/libmicrohttpd/
Other
101 stars 29 forks source link

cant get post binary data before submiting the response #14

Closed lbirkert closed 3 years ago

lbirkert commented 3 years ago

Im using libmicrohttpd to make an upload service and all i need is get the post data as a buffer (char*). But i have to firstly return MHD_YES and then i get access to the data, the problem is i have to submit the response before i get the data. How do i do that?

Karlson2k commented 3 years ago

If you use MHD_queue_response() before reading the request in full, MHD treats it as a signal "response is generated, application do not need the client upload" and discards the rest of the upload. You have a several ways to get full client upload:

  1. This is most straightforward approach. Read the full request. After reading the last upload block processes, the MHD_AccessHandlerCallback() will be called again with NULL as upload_data, you should provide response by MHD_queue_response(). Do not forget to destroy response once you queued it.
  2. If you have some specific reason to generate response before reading upload data, you can create response by MHD_create_response_from_xxx(), optionally enrich it by MHD_add_response_header(), and store it somewhere. You can create static response to be (re-)used for replies, or generate it for one time use only. If you generate response in your MHD_AccessHandlerCallback() you can use *con_cls pointer to store response. After you process the last part of the upload data, you can use MHD_queue_response() with pre-generated response.

Does it answer your needs?

lbirkert commented 3 years ago

Thanks a lot. Yeah it works now ^^