It worked! 😀

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;
}

$ curl --header "Content-Type:application/octet-stream" --trace-ascii
debugdump.txt --data-binary @content.bin http://localhost:9090

$ 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.

On Fri, Jan 5, 2018 at 12:59 AM, silvioprog <silviop...@gmail.com> wrote:

> Oh, I found a good explanation just after sensing my question:
>
> * @param[in,out] upload_data_size set initially to the size of the
> *        @a upload_data provided; the method must update this
> *        value to the number of bytes NOT processed;
>
> ... it seems I need to load the upload_data on demand. 🤔
>
> I'm going to test it and back with some feedback ...
>

-- 
Silvio Clécio

Reply via email to