Skip to content

Commit

Permalink
Expose Janus and Admin API ping request via GET too, when using HTTP (f…
Browse files Browse the repository at this point in the history
…ixes #3336)
  • Loading branch information
lminiero committed Feb 28, 2024
1 parent 2bfc7f9 commit 0c8333d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/transports/janus_http.c
Expand Up @@ -1537,6 +1537,25 @@ static MHD_Result janus_http_handler(void *cls, struct MHD_Connection *connectio
json_object_set_new(root, "transaction", json_string(tr));
goto parsingdone;
}
/* Or maybe a ping */
if(session_path != NULL && !strcmp(session_path, "ping")) {
/* The info REST endpoint, if contacted through a GET, provides information on the Janus core */
if(strcasecmp(method, "GET")) {
response = MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT);
janus_http_add_cors_headers(msg, response);
ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response);
MHD_destroy_response(response);
goto done;
}
/* Turn this into a fake "info" request */
method = "POST";
char tr[12];
janus_http_random_string(12, (char *)&tr);
root = json_object();
json_object_set_new(root, "janus", json_string("ping"));
json_object_set_new(root, "transaction", json_string(tr));
goto parsingdone;
}

/* Or maybe a long poll */
if(!strcasecmp(method, "GET") || !payload) {
Expand Down Expand Up @@ -1939,6 +1958,25 @@ static MHD_Result janus_http_admin_handler(void *cls, struct MHD_Connection *con
json_object_set_new(root, "transaction", json_string(tr));
goto parsingdone;
}
/* Or maybe a ping */
if(session_path != NULL && !strcmp(session_path, "ping")) {
/* The info REST endpoint, if contacted through a GET, provides information on the Janus core */
if(strcasecmp(method, "GET")) {
response = MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT);
janus_http_add_cors_headers(msg, response);
ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response);
MHD_destroy_response(response);
goto done;
}
/* Turn this into a fake "info" request */
method = "POST";
char tr[12];
janus_http_random_string(12, (char *)&tr);
root = json_object();
json_object_set_new(root, "janus", json_string("ping"));
json_object_set_new(root, "transaction", json_string(tr));
goto parsingdone;
}

/* Without a payload we don't know what to do */
if(!payload) {
Expand Down

0 comments on commit 0c8333d

Please sign in to comment.