- post.upload_data = upload_data;
- post.upload_data_size = upload_data_size;
-
-#if 0
- struct afb_hreq *previous;
-
- previous = *recorder;
- if (previous) {
- assert((void **)previous->recorder == recorder);
- assert(previous->session == session);
- assert(previous->connection == connection);
- assert(previous->method == get_method(methodstr));
- assert(previous->url == url);
-
- /* TODO */
-/*
- assert(previous->post_handler != NULL);
- previous->post_handler(previous, &post);
- return MHD_NO;
-*/
+ hreq = *recordreq;
+ if (hreq == NULL) {
+ /* create the request */
+ hreq = calloc(1, sizeof *hreq);
+ if (hreq == NULL)
+ goto internal_error;
+ *recordreq = hreq;
+
+ /* get the method */
+ method = get_method(methodstr);
+ method &= afb_method_get | afb_method_post;
+ if (method == afb_method_none)
+ goto bad_request;
+
+ /* init the request */
+ hreq->session = cls;
+ hreq->connection = connection;
+ hreq->method = method;
+ hreq->version = version;
+ hreq->tail = hreq->url = url;
+ hreq->lentail = hreq->lenurl = strlen(url);
+
+ /* init the post processing */
+ if (method == afb_method_post) {
+ type = afb_hreq_get_header(hreq, MHD_HTTP_HEADER_CONTENT_TYPE);
+ if (type == NULL) {
+ /* an empty post, let's process it as a get */
+ hreq->method = afb_method_get;
+ } else if (strcasestr(type, FORM_CONTENT) != NULL) {
+ hreq->postform = MHD_create_post_processor (connection, 65500, postproc, hreq);
+ if (hreq->postform == NULL)
+ goto internal_error;
+ } else if (strcasestr(type, JSON_CONTENT) == NULL) {
+ afb_hsrv_reply_error(connection, MHD_HTTP_UNSUPPORTED_MEDIA_TYPE);
+ return MHD_YES;
+ }
+ }