aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2015-12-30 11:20:26 +0100
committerFulup Ar Foll <fulup@iot.bzh>2015-12-30 11:20:26 +0100
commitbe2a72e7c9fdf339a89245c812b623985d70709c (patch)
tree88d9bdf71871197269afffee38561992551afd0b
parent93daafca4d0419707cdcde181180a689a7fccbfb (diff)
Added EmptyPost handling
-rw-r--r--include/local-def.h2
-rw-r--r--src/rest-api.c9
2 files changed, 5 insertions, 6 deletions
diff --git a/include/local-def.h b/include/local-def.h
index edaf1bbc..6d219406 100644
--- a/include/local-def.h
+++ b/include/local-def.h
@@ -107,7 +107,7 @@ typedef struct {
json_object *json;
} AFB_errorT;
-typedef enum {AFB_POST_NONE=0, AFB_POST_JSON, AFB_POST_FORM} AFB_PostType;
+typedef enum {AFB_POST_NONE=0, AFB_POST_JSON, AFB_POST_FORM, AFB_POST_EMPTY} AFB_PostType;
// Post Upload File Handle
typedef struct {
diff --git a/src/rest-api.c b/src/rest-api.c
index 2596f305..0c44a43e 100644
--- a/src/rest-api.c
+++ b/src/rest-api.c
@@ -45,7 +45,7 @@ PUBLIC void endPostRequest(AFB_PostHandle *postHandle) {
if (postHandle->type == AFB_POST_FORM) {
if (verbose) fprintf(stderr, "End PostForm Request UID=%d\n", postHandle->uid);
}
- free(postHandle->private);
+ if (postHandle->private) free(postHandle->private);
free(postHandle);
}
@@ -388,8 +388,8 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co
// We are facing an empty post let's process it as a get
if (encoding == NULL) {
- request= createRequest (connection, session, url);
- goto ProcessApiCall;
+ postHandle->type = AFB_POST_EMPTY;
+ return MHD_YES;
}
// Form post is handle through a PostProcessor and call API once per form key
@@ -466,11 +466,11 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co
errMessage = request->jresp;
goto ExitOnError;
}
+ postRequest.type = postHandle->type;
// Postform add application context handle to request
if (postHandle->type == AFB_POST_FORM) {
postRequest.data = (char*) postHandle;
- postRequest.type = postHandle->type;
request->post = &postRequest;
}
@@ -489,7 +489,6 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co
// Before processing data, make sure buffer string is properly ended
postHandle->private[postHandle->len] = '\0';
postRequest.data = postHandle->private;
- postRequest.type = postHandle->type;
request->post = &postRequest;
// if (verbose) fprintf(stderr, "Close Post[%d] Buffer=%s\n", postHandle->uid, request->post->data);