Just sharing the test for future references (smallest study code without any function result testing, don't use it in production!):
#include <microhttpd.h>
#include <stdio.h>
#include <string.h>
#define PAGE "<html><body>OK</body></html>"
#define FN "uploaded-stream.bin"
static size_t stofa(const char *fn, const char *s, size_t l, int a) {
FILE *fp;
fp = fopen(fn, (a ? "ab+" : "wb"));
l = fwrite(s, sizeof(char), l, fp);
fclose(fp);
return l;
}
static int atc(void *cls, struct MHD_Connection *con, const char *url, const char *verb, const char *ver,
const char *buf, size_t *off, void **p) {
struct MHD_Response *res;
int ret;
if (!*p) {
*p = (void *) 1;
return MHD_YES;
}
*p = NULL;
if (*off != 0) {
*off -= stofa(FN, buf, *off, access(FN, F_OK) != -1);
return MHD_YES;
}
res = MHD_create_response_from_buffer(strlen(PAGE), PAGE, MHD_RESPMEM_PERSISTENT);
ret = MHD_queue_response(con, MHD_HTTP_OK, res);
MHD_destroy_response(res);
return ret;
}
int main(void) {
unlink(FN);
struct MHD_Daemon *daemon;
daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, 9090, NULL, NULL, &atc, NULL, MHD_OPTION_END);
getchar();
MHD_stop_daemon(daemon);
return 0;
}
$ md5sum content.bin uploaded-stream.bin
b9c65bf433a37289d848a1f833a6b311 content.bin
b9c65bf433a37289d848a1f833a6b311 uploaded-stream.bin
ps. I know MHD_create_post_processor(), but the test is just receiving a binary stream sent via octet-stream.