[mod_verto] Support for JSON message body in the HTTP POST requst
This commit is contained in:
parent
44e228b31d
commit
4815f45767
|
@ -1765,7 +1765,13 @@ new_req:
|
|||
}
|
||||
|
||||
if (!strncmp(request->method, "POST", 4) && request->content_length && request->content_type) {
|
||||
switch_bool_t content_type_urlencoded = SWITCH_FALSE;
|
||||
switch_bool_t content_type_json = SWITCH_FALSE;
|
||||
|
||||
content_type_urlencoded = !strncmp(request->content_type, "application/x-www-form-urlencoded", 33);
|
||||
content_type_json = !strncmp(request->content_type, "application/json", 16);
|
||||
|
||||
if (content_type_urlencoded || content_type_json) {
|
||||
char *buffer = NULL;
|
||||
switch_ssize_t len = 0, bytes = 0;
|
||||
|
||||
|
@ -1796,24 +1802,15 @@ new_req:
|
|||
|
||||
*(buffer + bytes) = '\0';
|
||||
|
||||
// Supports both urlencoded and json message body in the http request
|
||||
if (!strncmp(request->content_type, "application/x-www-form-urlencoded", 33)) {
|
||||
if (content_type_urlencoded) {
|
||||
kws_parse_qs(request, buffer);
|
||||
} else if (!strncmp(request->content_type, "application/json", 16)) {
|
||||
cJSON *json = NULL;
|
||||
json = cJSON_Parse(buffer);
|
||||
if (json) {
|
||||
} else if (content_type_json) {
|
||||
switch_event_set_body(stream.param_event, buffer);
|
||||
cJSON_Delete(json);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid JSON data in message body. content_length: %ld, body: %s \n", request->content_length, buffer);
|
||||
free(buffer);
|
||||
goto request_err;
|
||||
}
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// kws_request_dump(request);
|
||||
|
||||
|
|
Loading…
Reference in New Issue