Allow non-json / x-pem requests and responses.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-05-04 01:01:30 +02:00
parent c4bffd5433
commit 0cc24a9637
2 changed files with 5 additions and 3 deletions

View File

@@ -207,7 +207,8 @@ int rest_execute_route_handler(const rest_request_t *request, rest_route_handler
response->json = NULL;
return -1;
}
if (response->status_code == 0 || response->status_code == 200 || response->status_code == 201 || response->status_code == 204) {
bool is_json_response = (response->content_type != NULL && strcmp(response->content_type, "application/json") == 0);
if (is_json_response && (response->status_code == 0 || response->status_code == 200 || response->status_code == 201 || response->status_code == 204)) {
char *body = cJSON_PrintUnformatted(response->json);
cJSON_Delete(response->json);
response->json = NULL;
@@ -222,6 +223,7 @@ int rest_execute_route_handler(const rest_request_t *request, rest_route_handler
}
}
response->body = body;
response->body_len = 0;
}
if (response->json != NULL) {
cJSON_Delete(response->json);
@@ -395,4 +397,4 @@ rest_route_handler_t rest_background_job_pop(void) {
}
}
return NULL;
}
}

View File

@@ -754,7 +754,7 @@ void rest_handle_request(rest_conn_t *conn) {
rest_debug_dump_payload("request-body", request->body, request->body_len);
if (request->method == REST_HTTP_POST || request->method == REST_HTTP_PUT) {
if (!rest_content_type_is_json(request->content_type)) {
if (!rest_content_type_is_json(request->content_type) && strncasecmp(request->content_type, "application/x-pem-file", 22) != 0) {
send_json_error(conn, 415, "content_type_must_be_application_json");
return;
}