Merge e1075b0ee3
into 3b58ebc5f3
This commit is contained in:
commit
e8890ff3a1
|
@ -1764,41 +1764,54 @@ new_req:
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(request->method, "POST", 4) && request->content_length && request->content_type &&
|
if (!strncmp(request->method, "POST", 4) && request->content_length && request->content_type) {
|
||||||
!strncmp(request->content_type, "application/x-www-form-urlencoded", 33)) {
|
switch_bool_t content_type_urlencoded = SWITCH_FALSE;
|
||||||
|
switch_bool_t content_type_json = SWITCH_FALSE;
|
||||||
|
|
||||||
char *buffer = NULL;
|
content_type_urlencoded = !strncmp(request->content_type, "application/x-www-form-urlencoded", 33);
|
||||||
switch_ssize_t len = 0, bytes = 0;
|
content_type_json = !strncmp(request->content_type, "application/json", 16);
|
||||||
|
|
||||||
if (request->content_length && request->content_length > 10 * 1024 * 1024 - 1) {
|
if (content_type_urlencoded || content_type_json) {
|
||||||
char *data = "HTTP/1.1 413 Request Entity Too Large\r\n"
|
char *buffer = NULL;
|
||||||
"Content-Length: 0\r\n\r\n";
|
switch_ssize_t len = 0, bytes = 0;
|
||||||
kws_raw_write(jsock->ws, data, strlen(data));
|
|
||||||
request->keepalive = 0;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(buffer = malloc(2 * 1024 * 1024))) {
|
if (request->content_length > 10 * 1024 * 1024 - 1) {
|
||||||
goto request_err;
|
char *data = "HTTP/1.1 413 Request Entity Too Large\r\n"
|
||||||
}
|
"Content-Length: 0\r\n\r\n";
|
||||||
|
|
||||||
while(bytes < (switch_ssize_t)request->content_length) {
|
kws_raw_write(jsock->ws, data, strlen(data));
|
||||||
len = request->content_length - bytes;
|
request->keepalive = 0;
|
||||||
|
|
||||||
#define WS_BLOCK 1
|
|
||||||
|
|
||||||
if ((len = kws_raw_read(jsock->ws, buffer + bytes, len, WS_BLOCK)) < 0) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error %" SWITCH_SSIZE_T_FMT"\n", len);
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes += len;
|
if (!(buffer = malloc(10 * 1024 * 1024))) {
|
||||||
|
goto request_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (bytes < (switch_ssize_t)request->content_length) {
|
||||||
|
len = request->content_length - bytes;
|
||||||
|
|
||||||
|
#define WS_BLOCK 1
|
||||||
|
|
||||||
|
if ((len = kws_raw_read(jsock->ws, buffer + bytes, len, WS_BLOCK)) < 0) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error %" SWITCH_SSIZE_T_FMT"\n", len);
|
||||||
|
free(buffer);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(buffer + bytes) = '\0';
|
||||||
|
|
||||||
|
if (content_type_urlencoded) {
|
||||||
|
kws_parse_qs(request, buffer);
|
||||||
|
} else if (content_type_json) {
|
||||||
|
switch_event_set_body(stream.param_event, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
*(buffer + bytes) = '\0';
|
|
||||||
|
|
||||||
kws_parse_qs(request, buffer);
|
|
||||||
free(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// kws_request_dump(request);
|
// kws_request_dump(request);
|
||||||
|
|
Loading…
Reference in New Issue